Commit b56987e
OpenID Connect support (#915)
* Openid Connect Core support - Round 3
* Add OpenID connect hybrid grant type
* Add OpenID connect algorithm type to Application model
* Add OpenID connect id token model
* Add nonce Authorization as required by OpenID connect Implicit Flow
* Add body to create_authorization_response to pass nonce and future OpenID parameters to oauthlib.common.Request
* Add OpenID connect ID token creation and validation methods and scopes
* Add OpenID connect response types
* Add OpenID connect authorization code flow test
* Add OpenID connect implicit flow tests
* Add validate_user_match method to OAuth2Validator
* Add RSA_PRIVATE_KEY setting with blank value
* Update tox
* Add get_jwt_bearer_token to OAuth2Validator
* Add validate_jwt_bearer_token to OAuth2Validator
* Change OAuth2Validator.validate_id_token default return value to False to avoid validation security breach
* Change to use .encode to avoid py2.7 tox test error
* Add OpenID connect hybrid flow tests
* Change to use .encode to avoid py2.7 tox test error
* Add RSA_PRIVATE_KEY to the list of settings that cannot be empt
* Add support for oidc connect discovery
* Use double quotes for strings
* Rename migrations to avoid name and order conflict
* Remove commando to install OAuthLib from master and removed jwcrypto duplication
* Remove python 2 compatible code
* Change errors access_denied/unauthorized_client/consent_required/login_required to be 400 as changed in oauthlib/pull/623
* Change iss claim value to come from settings
* Change to use openid connect code server class
* Change test to include missing state
* Add id_token relation to AbstractAccessToken
* Add claims property to AbstractIDToken
* Change OAuth2Validator._create_access_token to save id_token to access_token
* Add userinfo endpoint
* Update migrations and remove oauthlib duplication
* Remove old generated migrations
* Add new migrations
* Fix tests
* Add nonce to hybrid tests
* Add missing new attributes to test migration
* Rebase fixing conflicts and tests
* Remove auto generate message
* Fix flake8 issues
* Fix test doc deps
* Add project settings to be ignored in coverage
* Tweak migrations to support non-overidden models
* OIDC_USERINFO_ENDPOINT is not mandatory
* refresh_token grant should be support for OpenID hybrid
* Fix the user info view, and remove hard dependency on DRF
* Use proper URL generation for OIDC endpoints
* Support rich ID tokens and userinfo claims
Extend the validator and override get_additional_claims based on your own user model.
* Bug fix for at_hash generation
See https://openid.net/specs/openid-connect-core-1_0.html#id_token-tokenExample to prove algorithm
* OIDC_ISS_ENDPOINT is an optional setting
* Support OIDC urls from issuer url if provided
* Test for generated OIDC urls
* Flake
* Rebase on master and migrate url function to re_path
* Handle invalid token format exceptions as invalid tokens
* Merge migrations and sort imports isort for flake8 lint check
Co-authored-by: Dave Burkholder <dave@thinkwelldesigns.com>
Co-authored-by: Wiliam Souza <wiliamsouza83@gmail.com>
Co-authored-by: Allisson Azevedo <allisson@gmail.com>
Co-authored-by: fvlima <frederico.vieira@gmail.com>
Co-authored-by: Shaun Stanworth <shaun.stanworth@googlemail.com>
* Make IDToken admin class swappable
* Make OIDC support optional
Make OIDC support optional by not requiring OIDC_RSA_PRIVATE_KEY to be
set in the settings, and using the standard oauthlib.oauth2.Server class
when an OIDC private key is not configured.
Add a test fixture wrapping oauth2_settings. This allows individual
tests / test suites to override oauth2 settings and have them reset at
the end of the test. This avoids configuration leaking from one test to
another, and allows us to test multiple different configurations in one
test run.
When using the oauth2_settings fixture, allow configuration for the test
case to be loaded from a pytest marker called oauth2_settings.
Split out OIDC specific tests requiring specific OIDC configuration into
separate TestCase.
Adjust the OAuthLibMixin to fallback to using the server, validator and
core classes specified in oauth2_settings when not hardcoded in to the
class. These classes can still be specified as hard-coded attributes in
sub-classes, but it's no longer required if you just want what is
configured in oauth2_settings, so remove all attributes that are just
pointing at the configuration anyway.
Add a setting ALWAYS_RELOAD_OAUTHLIB_CORE, which causes OAuthLibMixin to
reload the OAuthLibCore object on each request. This is only intended to
be used during testing, to allow the views to recognise changes in
configuration.
Show missing coverage lines in the coverage report.
Fixes: #873
* Add tests for OIDC userinfo view
* Add test for creating the OIDC issuer url for JWTs
* Add ID token generation and validation tests
* Add tests for OAuth2ProviderSettings
* Add tests for IDToken model methods
* Remove unnecessary __future__ declarations
* Enable OIDC only views only when using OIDC
Add a mixin for OIDC only views that checks that OIDC is correctly
configured before allowing the request to continue.
If OIDC is not enabled, raise an ImproperlyConfigured exception if the
site is in DEBUG mode, otherwise log a warning and return a 404
response.
* Remove mistakenly committed comment
* Add OIDC documentation
* Add OIDC support change to CHANGELOG.md
* Support nonce and claims in OIDC auth
* Add nonce and claims fields to Grant model.
* Complete support for nonce in the OIDC auth code flow, and work around
an oauthlib bug in the OIDC hybrid flow that caused a nonce presented
in the authentication endpoint to be omitted from the ID token.
* Switch to using `RequestValidator.finalize_id_token` instead of
`RequestValidator.get_id_token`. This allows us to use the oauthlib
stock implementation of `get_id_token`, which creates `at_hash` and
`c_hash` when appropriate.
* Support `claims` in the authentication endpoint to specify what claims
are desired in the ID token, as per section 5.5. Interpreting the
claims parameter is up to implementers.
* Add documentation on using scopes and claims as authentication
endpoint parameters to influence what claims to add to the tokens.
* Add tests for `nonce` and `claims` handling.
* Fix py3.5 tests getting scopes in unexpected order
Not entirely sure how my previous changes caused that, but convert them
to sets and compare the sets of scopes.
* Simplify and optimise get_authorization_code_scopes
`code` is sufficient for retrieving an auth code's scopes, and we don't
need to do two DB queries where one will suffice.
* Serve JWKs using well-known URL
JWKs are commonly served from `.well-known/jwks.json`. This isn't a
standard, but it is in common usage so it makes sense to conform.
* Allow POST for OIDC UserInfo endpoint
* Refactor how OIDC issuer url is generated
Split out how to generate the OIDC issuer (when not specified in
settings) out to a util function.
Add tests
Dont use reverse_lazy when the next thing we do with the url is to
format it in to a string - no time for it to be lazy!
* Support HS256 for OIDC
* Add full support for HS256 signed OIDC keys.
* Add a new default signing algorithm, NO_ALGORITHM.
* Add docs on why you shouldn't choose HS256, and how to do it anyway.
* Add docs on how to enable an app for OIDC.
* Remove OIDC_ID_TOKEN_SIGNING_ALG_VALUES_SUPPORTED and generate it
depending on whether you have added an RSA key.
* Add validation for your application signing algorithm so its not
possible to accidentally setup something insecure.
* Add `Application.jwk_key` property to load the correct key for an
application.
* Peek at a supplied id_token to determine the application it belongs to
so that we can load the correct key to verify the signature.
* Add an OIDC_ENABLED setting, as we can now enable OIDC without adding
OIDC_RSA_PRIVATE_KEY.
* Update and add new tests.
* fix: json.loads on python 3.5 requires a str
* Remove changes to create_authorization_response
When using OIDC, the additional parameters nonce and claims are
correctly extracted by oauthlib, we don't need to manually parse them
out and pass them as a phony body parameter.
Similarly, the django request is passed down to the final wrapper layer
that calls create_authorization_response in oauthlib, we can defer
calling `request.get_raw_uri()` until that point and drop passing `uri`
down two function calls.
This reverts create_authorization_response back to basically how it was
pre-OIDC changes.
* Reduce changes compared to master
There were a few other places where stylistic changes have been made that
are not a part of the changes. Revert them to make the patch less
different compared to master.
* Use simpler import name for oauthlib OIDC server
* Fix another reference to oauthlib.openid.Server
* Add indirect six dependency from jwcrpyto
jwcrypto has a direct dependency on six, but does not list it yet in a
release. Previously, cryptography also depended on six, so this was
unnoticed.
* Django master now supports only python 3.8+
* Store jti instead of the ID token contents
Add a jti parameter to each ID token generated. After verifying a
received ID token JWT, extract the jti claim to verify that the ID token
exists in our database and is not expired.
We don't require the contents of the JWT to verify that an ID token
hasn't expired or been revoked, just the jti claim, so don't bother to
store or index the ID token contents. Because we only would look at this
when presented with an ID token JWT, all the claim contents are
available in this JWT.
Add missing scope check when verifying an ID token, add tests to verify
this.
Add functions _load_id_token and _load_access_token to OAuth2Validator,
analagous to _save_id_token and _create_access_token. These can be
overridden in sub-classes to customise loading behaviour, if these
models have been swapped.
* Code review changes
* Don't swallow ValueError in ClientProtectedResourceMixin
* Use OAuthLibCore._get_escaped_full_path to encode URI before passing
to oauthlib.
* You cannot create an ID Token using client credentials flow, so remove
dead code handling this eventuality from OAuth2Validator._save_id_token
* Remove TODO comment about saving IDTokens, it isn't necessary.
* Generate the correct issuer URL from oauthlib
OAuthlib will use OAuth2Validator.get_oidc_issuer_endpoint to generate
the issuer endpoint; we create a phony django request to use django's
mechanisms for generating the fully qualified URL. However, when SSL is
enableld, not enough information is passed through to determine that the
protocol is HTTPS.
Adjust OAuthLibCore.extract_headers() to inject a custom header when the
django request is secure. Use this extra header when generating the
issuer URL to determine whether to set the protocol to "https", and use
a custom django.http.HttpRequest subclass to allow us to set this.
Adjust OAuthLibCore.create_authorization_response() to pass through
headers to oauthlib to allow this header to be received.
* Update OIDC docs
* Krl/oidc round three fixes (#1)
Add kid to id_token header, conditional on the algorithm used
* Fix linting from PR
* Handle invalid tokens in userinfo endpoint
* Update a comment
Co-authored-by: Dave Burkholder <dave@thinkwelldesigns.com>
Co-authored-by: Wiliam Souza <wiliamsouza83@gmail.com>
Co-authored-by: Allisson Azevedo <allisson@gmail.com>
Co-authored-by: fvlima <frederico.vieira@gmail.com>
Co-authored-by: Shaun Stanworth <shaun.stanworth@googlemail.com>
Co-authored-by: Alan Crosswell <alan@columbia.edu>
Co-authored-by: Kristian Rune Larsen <67627991+kristianrunelarsen@users.noreply.github.com>1 parent c0a9ac9 commit b56987e
File tree
51 files changed
+3860
-257
lines changed- docs
- oauth2_provider
- migrations
- views
- tests
- migrations
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
51 files changed
+3860
-257
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
0 commit comments