-
Notifications
You must be signed in to change notification settings - Fork 3
Added fixes to Token Handling #8
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
Open
NickolausDS
wants to merge
3
commits into
fair-research:master
Choose a base branch
from
NickolausDS:introspection-fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,40 @@ | ||
| from app import app | ||
|
|
||
| try: | ||
| import globus_sdk | ||
| GLOBUS_AUTH_ENABLED = bool(app.config.get('GLOBUS_CLIENT_ID') and | ||
| app.config.get('GLOBUS_CLIENT_SECRET')) | ||
| except ImportError: | ||
| GLOBUS_AUTH_ENABLED = False | ||
|
|
||
| def validate_globus_user(email, authorization_header): | ||
| try: | ||
| type, code = authorization_header.split() | ||
| if str(type) != 'Bearer': | ||
| raise AuthorizationException('Only Bearer tokens are supported ' | ||
| 'for Globus Auth', | ||
| user=email, type='InvalidToken') | ||
|
|
||
| import globus_sdk # noqa | ||
| ac = globus_sdk.AuthClient( | ||
| authorizer=globus_sdk.AccessTokenAuthorizer(code)) | ||
| def validate_globus_user(email, authorization_header): | ||
|
|
||
| try: | ||
| idents = ac.get_identities(email).get('identities') | ||
| if not idents: | ||
| raise AuthorizationException('User needs to link their email ' | ||
| '%s to their Globus identity: ' | ||
| 'globus.org/app/account' % email, | ||
| user=email, | ||
| type='InvalidIdentity') | ||
| except globus_sdk.exc.AuthAPIError: | ||
| raise AuthorizationException('Expired or invalid Globus Auth ' | ||
| 'code.', user=email, | ||
| type='AuthorizationFailed') | ||
| except (ValueError, AttributeError): | ||
| raise AuthorizationException('Invalid Globus Authorization Header.', | ||
| scheme, token = authorization_header.split() | ||
| if str(scheme) != 'Bearer': | ||
| raise AuthorizationException('Only Bearer token scheme is supported ' | ||
| 'for Globus Auth', | ||
| user=email, type='InvalidToken') | ||
| client = globus_sdk.ConfidentialAppAuthClient( | ||
| app.config.get('GLOBUS_CLIENT_ID'), | ||
| app.config.get('GLOBUS_CLIENT_SECRET') | ||
| ) | ||
| info = client.oauth2_token_introspect(token, 'identity_set') | ||
| if info.data.get('active') is False: | ||
| raise AuthorizationException('Expired or invalid Globus Auth ' | ||
| 'code.', user=email, | ||
| type='AuthorizationFailed') | ||
| ids = client.get_identities(ids=info.data['identity_set']) | ||
| linked_emails = [str(u_id['email']) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Originally this was set to |
||
| for u_id in ids['identities']] | ||
| if email not in linked_emails: | ||
| # We're assuming the user just needs to link their id. It's | ||
| # possible they're an impersonator and we should raise an error | ||
| raise AuthorizationException('User needs to link their email ' | ||
| '%s to their Globus identity: ' | ||
| 'globus.org/app/account' % email, | ||
| user=email, | ||
| type='InvalidHeader') | ||
| except ImportError: | ||
| print('Please install Globus: "pip install globus_sdk"') | ||
| raise AuthorizationException('Server is misconfigured to use ' | ||
| 'Globus Auth, please notify ' | ||
| 'the administrator. Sorry.', user=email, | ||
| code=500, type='ServerError') | ||
| type='InvalidIdentity') | ||
|
|
||
|
|
||
| class AuthorizationException(Exception): | ||
|
|
||
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,33 @@ | ||
| class Config(object): | ||
| """Don't store your secrets here! Instead, create a file called | ||
| 'local_config.py' which will override settings below and isn't | ||
| tracked by git to avoid accidental VC checkins. | ||
| """ | ||
| DEBUG = True | ||
| TESTING = True | ||
|
|
||
| SQLALCHEMY_DATABASE_URI = "sqlite:////tmp/minid.db" | ||
| SQLALCHEMY_TRACK_MODIFICATIONS = True | ||
|
|
||
| HOSTNAME = "http://localhost:5000/minid" | ||
| PORT = 5000 | ||
| LANDING_PAGE = "http://localhost:5000/minid/landingpage" | ||
|
|
||
| GLOBUS_CLIENT_ID = "a5cdede9-567f-4ae5-aba5-cb997d08693a" | ||
| GLOBUS_CLIENT_SECRET = "" | ||
|
|
||
| EZID_SERVER = "https://ezid.cdlib.org" | ||
| EZID_SCHEME = "ark:/" | ||
| EZID_SHOULDER = "99999/fk4" | ||
| EZID_USERNAME = "apitest" | ||
| EZID_PASSWORD = "apitest" | ||
|
|
||
| TEST_EZID_SERVER = "https://ezid.cdlib.org" | ||
| TEST_EZID_SCHEME = "ark:/" | ||
| TEST_EZID_SHOULDER = "99999/fk4" | ||
| TEST_EZID_USERNAME = "apitest" | ||
| TEST_EZID_PASSWORD = "apitest" | ||
|
|
||
| AWS_ACCESS_KEY_ID = "" | ||
| AWS_SECRET_ACCESS_KEY = "" | ||
|
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
GLOBUS_AUTH_ENABLEDconfig option was removed. Not including a Client ID or Secret does effectively the same thing.