-
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.
- Loading branch information
Showing
9 changed files
with
819 additions
and
737 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
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
Large diffs are not rendered by default.
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
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 @@ | ||
"""Authentication module.""" |
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,43 @@ | ||
"""Implement OAuth handlers.""" | ||
|
||
import jwt | ||
import requests | ||
from flask import current_app | ||
|
||
|
||
def info_handler(remote_app, response_data): | ||
"""Extract account info from authorisation response. | ||
Extracts and validates the id_token returned as part of the OIDC workflow using | ||
metadata from the OpenId provider. Claims from the JWT are then returned in the | ||
expected structure for user sign-up process. | ||
Requires the following claims to be present in the id_token: email, | ||
preferred_username, name and oid. | ||
""" | ||
oidc_config = requests.get(current_app.config["ICL_OAUTH_WELL_KNOWN_URL"]).json() | ||
signing_algos = oidc_config["id_token_signing_alg_values_supported"] | ||
jwks_client = jwt.PyJWKClient(oidc_config["jwks_uri"]) | ||
|
||
id_token = response_data["id_token"] | ||
signing_key = jwks_client.get_signing_key_from_jwt(id_token) | ||
|
||
data = jwt.api_jwt.decode( | ||
id_token, | ||
key=signing_key.key, | ||
algorithms=signing_algos, | ||
audience=remote_app.consumer_key, | ||
) | ||
|
||
return dict( | ||
user=dict( | ||
email=data["email"], | ||
profile=dict( | ||
username=data["preferred_username"].rstrip("@ic.ac.uk"), | ||
full_name=data["name"], | ||
), | ||
), | ||
external_id=data["oid"], | ||
external_method="icl_sso", | ||
active=True, | ||
) |
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 was deleted.
Oops, something went wrong.