-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔏 Requires valid access tokens for API calls (#173)
* Requires valid access tokens for API calls * Adds a dependency function called `permissions` that allows API endpoints to require specific permissions. * A permissions is a combination of an action and a resource type, delimited by a colon, for instance "read:messages". * The permissions() dependency function takes a single permission string, or a list of them. * POST /api/events/ now requiress "create:event" permission * POST /api/sony_ci/sync now requires "sync:sony_ci" permission * The "permissions" dependency can be added to any API endpoint like this: `@app.get('/users/', dependencies=[Depends(permissions('read:users'))])` * The "permissions" dependency in turn depends on a verified access token, which is verified by fetching the unverified access token from the HTTP request header and verifying it with the well-known public key provided by Auth0. * NOTE: for testing, the verified access token dependency is overridden to avoid depending on live connection with Auth0 for tests. * Adds tests for testing the authentication and authorization dependencies of the API endpoints. * The testing pattern involves a factory for generating a fake access tokens with whatever permissions the test is concerned with testing. Also: * Removes unused launch config for tests. Use vscode pytest settings instead. * Changes param name from allow_redirects to follow_redirects to fix deprecation warning * Adds git-guardian cache dir to git ignore * Adds constants to config used for verifying access token and specifying the authorization 'audience'. * Renames admin_user dependency to to 'get_admin_user' for consistency. * Renames get_user to get_oauth_user for specificity -- i.e. not a User model from the Chowda db. * Adds pyjwt for dealing with Javascript Web Tokens (jwt). * Removes test for api calls to create batches - not needed. * Removes .env files from revision, but leaves a sample template: '.env.sample'. * Prefixes all env vars and constants having to do with Auth0 with "AUTH0_" for consistency. * Sets test db used in github CI workflow to use name 'chowda' and default port 5432. Closes #153. --------- Co-authored-by: Harpo Harbert <[email protected]>
- Loading branch information
Showing
21 changed files
with
835 additions
and
524 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Postgres URL for Chowda DB. | ||
# Format: postgresql://{user}:{password}@{host}:{port}/{database} | ||
DB_URL='' | ||
|
||
# Env vars beginning with "AUTH0_" are used for authentication and authorization with Auth0. | ||
# These values can be obtained by logging into our Auth0 account. | ||
AUTH0_DOMAIN='' | ||
AUTH0_CLIENT_ID='' | ||
AUTH0_CLIENT_SECRET='' | ||
AUTH0_API_AUDIENCE='' | ||
|
||
# Secret value for securing session data using SessionMiddleware | ||
CHOWDA_SECRET='' |
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 |
---|---|---|
|
@@ -23,4 +23,9 @@ ci.toml | |
|
||
# Metaflow generated files | ||
metaflow.s3.* | ||
.metaflow | ||
.metaflow | ||
|
||
.cache_ggshield | ||
|
||
.env.* | ||
!.env.sample |
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
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
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
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.