-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New backend for the WLCG IAM testing site (#820)
* New backend for the WLCG IAM testing site * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update wlcg.py Adding email scope in default scope * Adding test for wlcg backend Co-authored-by: Maiken Pedersen <[email protected]>
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from urllib.parse import urlencode | ||
|
||
from .oauth import BaseOAuth2 | ||
|
||
|
||
class WLCGOAuth2(BaseOAuth2): | ||
""" | ||
WLCG IAM Authentication Backend | ||
""" | ||
|
||
name = "wlcg" | ||
API_URL = "https://wlcg.cloud.cnaf.infn.it" | ||
AUTHORIZATION_URL = "https://wlcg.cloud.cnaf.infn.it/authorize" | ||
ACCESS_TOKEN_URL = "https://wlcg.cloud.cnaf.infn.it/token" | ||
REFRESH_TOKEN_URL = "https://wlcg.cloud.cnaf.infn.it/token" | ||
ACCESS_TOKEN_METHOD = "POST" | ||
DEFAULT_SCOPE = ["openid", "email", "profile", "wlcg", "offline_access"] | ||
REDIRECT_STATE = False | ||
|
||
def get_user_details(self, response): | ||
"""Return user details from WLCG IAM service""" | ||
fullname, first_name, last_name = self.get_user_names( | ||
first_name=response.get("given_name"), last_name=response.get("family_name") | ||
) | ||
return { | ||
"username": response.get("email"), | ||
"email": response.get("email"), | ||
"fullname": fullname, | ||
"first_name": first_name, | ||
"last_name": last_name, | ||
} | ||
|
||
def user_data(self, access_token, *args, **kwargs): | ||
"""Loads user data from service""" | ||
url = "https://wlcg.cloud.cnaf.infn.it/userinfo?" + urlencode( | ||
{"access_token": access_token} | ||
) | ||
return self.get_json(url) |
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,30 @@ | ||
import json | ||
|
||
from .oauth import OAuth2Test | ||
|
||
|
||
class WLCGOAuth2Test(OAuth2Test): | ||
backend_path = "social_core.backends.wlcg.WLCGOAuth2" | ||
user_data_url = "https://wlcg.cloud.cnaf.infn.it/userinfo" | ||
expected_username = "[email protected]" | ||
access_token_body = json.dumps( | ||
{ | ||
"access_token": "foobar", | ||
"token_type": "bearer", | ||
} | ||
) | ||
user_data_body = json.dumps( | ||
{ | ||
"email": "[email protected]", | ||
"family_name": "Bar", | ||
"given_name": "Foo", | ||
"name": "Foo Bar", | ||
"email_verified": True, | ||
} | ||
) | ||
|
||
def test_login(self): | ||
self.do_login() | ||
|
||
def test_partial_pipeline(self): | ||
self.do_partial_pipeline() |