-
Notifications
You must be signed in to change notification settings - Fork 9
Support OAuth authentication method #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1eca75b
Support OAuth authentication method
guyp-descope 07315dc
add tests
guyp-descope cf56d98
add request body+header testing (for oauth)
guyp-descope 01dec9d
Fix PR comments
guyp-descope d4e51ea
1. add check for empty ds/dsr cookies on logout flow. 2. optimize the…
guyp-descope c30b2cb
fix tests
guyp-descope eb66ce5
PR fixes
guyp-descope File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,65 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| from flask import Flask, jsonify | ||
|
|
||
| dir_name = os.path.dirname(__file__) | ||
| sys.path.insert(0, os.path.join(dir_name, "../")) | ||
| from decorators.flask_decorators import ( # noqa: E402; | ||
| descope_logout, | ||
| descope_oauth, | ||
| descope_validate_auth, | ||
| ) | ||
|
|
||
| from descope import AuthClient # noqa: E402 | ||
|
|
||
| APP = Flask(__name__) | ||
|
|
||
| PROJECT_ID = "" | ||
|
|
||
| # init the AuthClient | ||
| auth_client = AuthClient(PROJECT_ID) | ||
|
|
||
|
|
||
| class Error(Exception): | ||
| def __init__(self, error, status_code): | ||
| self.error = error | ||
| self.status_code = status_code | ||
|
|
||
|
|
||
| @APP.errorhandler(Error) | ||
| def handle_auth_error(ex): | ||
| response = jsonify(ex.error) | ||
| response.status_code = ex.status_code | ||
| return response | ||
|
|
||
|
|
||
| # This needs authentication | ||
| @APP.route("/api/private") | ||
| @descope_validate_auth(auth_client) | ||
| def private(): | ||
| response = "This is a private API and you must be authenticated to see this" | ||
| return jsonify(message=response) | ||
|
|
||
|
|
||
| @APP.route("/api/logout") | ||
| @descope_logout(auth_client) | ||
| def logout(): | ||
| response = "Logged out" | ||
| return jsonify(message=response) | ||
|
|
||
|
|
||
| @APP.route("/api/oauth", methods=["GET"]) | ||
| @descope_oauth(auth_client) | ||
| def oauth(*args, **kwargs): | ||
| pass | ||
|
|
||
|
|
||
| # This doesn't need authentication | ||
| @APP.route("/") | ||
| def home(): | ||
| return "OK" | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| APP.run(host="127.0.0.1", port=9000) |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.