-
Notifications
You must be signed in to change notification settings - Fork 48
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
124 additions
and
3 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
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,21 @@ | ||
import flask | ||
|
||
from fence.blueprints.login.base import DefaultOAuth2Login, DefaultOAuth2Callback | ||
|
||
CILOGON_IDP_NAME = "cilogon" | ||
|
||
|
||
class CilogonLogin(DefaultOAuth2Login): | ||
def __init__(self): | ||
super(CilogonLogin, self).__init__( | ||
idp_name=CILOGON_IDP_NAME, client=flask.current_app.cilogon_client | ||
) | ||
|
||
|
||
class CilogonCallback(DefaultOAuth2Callback): | ||
def __init__(self): | ||
super(CilogonCallback, self).__init__( | ||
idp_name=CILOGON_IDP_NAME, | ||
client=flask.current_app.cilogon_client, | ||
username_field="sub", | ||
) |
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,51 @@ | ||
from .idp_oauth2 import Oauth2ClientBase | ||
|
||
|
||
class CilogonOauth2Client(Oauth2ClientBase): | ||
""" | ||
client for interacting with CILogon OIDC | ||
""" | ||
|
||
CILOGON_DISCOVERY_URL = "https://cilogon.org/.well-known/openid-configuration" | ||
|
||
def __init__(self, settings, logger, HTTP_PROXY=None): | ||
super(CilogonOauth2Client, self).__init__( | ||
settings, | ||
logger, | ||
scope="openid email profile", | ||
discovery_url=self.CILOGON_DISCOVERY_URL, | ||
idp="CILogon", | ||
HTTP_PROXY=HTTP_PROXY, | ||
) | ||
|
||
def get_auth_url(self): | ||
""" | ||
Get authorization uri from discovery doc | ||
""" | ||
authorization_endpoint = self.get_value_from_discovery_doc( | ||
"authorization_endpoint", "https://cilogon.org/authorize" | ||
) | ||
|
||
uri, _ = self.session.create_authorization_url( | ||
authorization_endpoint, prompt="login" | ||
) | ||
|
||
return uri | ||
|
||
def get_user_id(self, code): | ||
try: | ||
token_endpoint = self.get_value_from_discovery_doc( | ||
"token_endpoint", "https://cilogon.org/oauth2/token" | ||
) | ||
jwks_endpoint = self.get_value_from_discovery_doc( | ||
"jwks_uri", "https://cilogon.org/oauth2/certs" | ||
) | ||
claims = self.get_jwt_claims_identity(token_endpoint, jwks_endpoint, code) | ||
|
||
if claims["sub"]: | ||
return {"sub": claims["sub"]} | ||
else: | ||
return {"error": "Can't get user's CILogon sub"} | ||
except Exception as e: | ||
self.logger.exception("Can't get user info") | ||
return {"error": "Can't get your CILogon sub: {}".format(e)} |
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