-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PXP-6617 Add custom scopes validation and revert aud validation to de…
…fault (#47) * feat(scope): Add class JWTScopeError(JWTError) * fix(aud): Validate aud claim the normal way, validate custom scopes claim * import new JWTScopeError * add new scope arg to core.validate_jwt * add new scope validation to core.validate_jwt * remove custom aud validation from core.validate_jwt * remove random_aud hack in core.validate_jwt; type(aud) now string-or-None, not set-or-list * pass aud through to PyJWT for normal validation * update docstring for core.validate_jwt * allow empty aud arg in validate.validate_jwt; cease raising ValueError * add new optional scope arg in validate.validate_jwt; pass through to core.validate_jwt * update docstring for validate.validate_jwt * fix(aud): allow passthrough of options arg to pyjwt * fix(aud-scope): switch require_auth_header to checking scopes not aud * fix(aud-scope): Skip aud validation in require_auth_header/validate_request * test(aud-scope): Change default_audiences fixture to default_scopes; rm aud from generic claims * fix(aud-scope): chg aud to scope in FastAPI access_token dependency * test(aud-scope): Upd tests to reflect new aud/scope usage * fix(aud-scope): chg aud to scope in CurrentUser call to validate_request * test(aud): add happy-path test for aud validation * style(black): Blacken, and update black rev in precommit config * test(aud): Explicitly pass None instead of default_audiences * because default_audience may change to not None in future * and because this better reflects the intention of the test * fix(aud): Re-enable aud claim validation in require_auth_header * fix(aud): Expect iss in aud claim by default in token.validate_jwt... * ...if a value for iss is avbl, from app cfg BASE_URL or USER_API. * Also clarify core.validate_jwt docstring. * test(app-fixture): Set app.config['BASE_URL'] as well as ['USER_API'] * fix(aud): Allow passing expected audience to FastAPI access_token dependency * test(aud): Include aud claim in default claims test fixture * Update default_audience fixture accordingly * Update tests to account for new default claims * fix(aud): Allow passing expected audience to require_auth_header and validate_request * Also let scope={} by default * Update calls to require_auth_header * fix(aud): Update set_current_user proxy fn to pass in expected aud * based on flask.current_app.config * Since this already assumes Flask request ctx, I think OK to look in Flask app cfg in this case * test(aud): Add test: no aud arg provided and no aud claim in token * test(aud): Rename fixture default_audiences to default_audience * chore(precommit): pre-commit autoupdate * fix(aud): fix incorrect kwargs logic * docs(aud): add missing audience arg to docstring * test(aud): use default_audience instead of iss in claims fixture * fix(aud-scope): error message Co-authored-by: Pauline Ribeyre <ribeyre@uchicago.edu> * docs(aud-scope): Fix docstring Co-authored-by: Pauline Ribeyre <ribeyre@uchicago.edu> Co-authored-by: Pauline Ribeyre <ribeyre@uchicago.edu>
- Loading branch information
1 parent
c5adb41
commit 2b7538e
Showing
10 changed files
with
333 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
repos: | ||
- repo: git@github.com:Yelp/detect-secrets | ||
rev: v0.13.1 | ||
rev: v1.1.0 | ||
hooks: | ||
- id: detect-secrets | ||
args: ['--baseline', '.secrets.baseline'] | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.5.0 | ||
rev: v3.4.0 | ||
hooks: | ||
- id: end-of-file-fixer | ||
- id: no-commit-to-branch | ||
args: [--branch, develop, --branch, master, --pattern, release/.*] | ||
- repo: https://github.com/psf/black | ||
rev: 19.10b0 | ||
rev: 20.8b1 | ||
hooks: | ||
- id: black |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,8 @@ class JWTPurposeError(JWTError): | |
class JWTAudienceError(JWTError): | ||
|
||
pass | ||
|
||
|
||
class JWTScopeError(JWTError): | ||
|
||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.