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
6 changed files
with
96 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
loginpass.hydra | ||
~~~~~~~~~~~~~~~~ | ||
Loginpass Backend of Ory Hydra (https://ory.sh) and its | ||
enterprise endpoints. | ||
Useful Links: https://www.ory.sh/docs/hydra/sdk/api | ||
- API documentation: https://www.ory.sh/docs/hydra/sdk/api | ||
:license: BSD, see LICENSE for more details. | ||
""" | ||
|
||
from ._core import UserInfo, OAuthBackend | ||
|
||
|
||
def create_hydra_backend(name, hostname): | ||
"""Build Hydra OAuth Backend.""" | ||
api_base_url = 'https://{hostname}'.format(hostname=hostname) | ||
authorize_url = 'https://{hostname}/oauth2/auth'.format(hostname=hostname) | ||
token_url = 'https://{hostname}/oauth2/token'.format(hostname=hostname) | ||
|
||
class Hydra(OAuthBackend): | ||
OAUTH_TYPE = '2.0,oidc' | ||
OAUTH_NAME = name | ||
OAUTH_CONFIG = { | ||
'api_base_url': api_base_url, | ||
'access_token_url': token_url, | ||
'authorize_url': authorize_url | ||
# customisations can added in client kwargs | ||
} | ||
|
||
def profile(self, **kwargs): | ||
resp = self.get('userinfo', **kwargs) | ||
resp.raise_for_status() | ||
data = resp.json() | ||
if not kwargs.get('param_keys'): | ||
params = data | ||
else: | ||
params = {k: data[k] for k in kwargs.get('param_keys')} | ||
|
||
return UserInfo(params) | ||
|
||
return Hydra |
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 @@ | ||
{ | ||
"birthdate": "string", | ||
"email": "string", | ||
"email_verified": true, | ||
"family_name": "string", | ||
"gender": "string", | ||
"given_name": "string", | ||
"locale": "string", | ||
"middle_name": "string", | ||
"name": "string", | ||
"nickname": "string", | ||
"phone_number": "string", | ||
"phone_number_verified": true, | ||
"picture": "string", | ||
"preferred_username": "string", | ||
"profile": "string", | ||
"sub": "string", | ||
"updated_at": 0, | ||
"website": "string", | ||
"zoneinfo": "string" | ||
} |
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 @@ | ||
{ | ||
"birthdate": "string", | ||
"email": "string", | ||
"email_verified": true, | ||
"family_name": "string", | ||
"gender": "string", | ||
"given_name": "string", | ||
"locale": "string", | ||
"middle_name": "string", | ||
"name": "string", | ||
"nickname": "string", | ||
"phone_number": "string", | ||
"phone_number_verified": true, | ||
"picture": "string", | ||
"preferred_username": "string", | ||
"profile": "string", | ||
"sub": "string", | ||
"updated_at": 0, | ||
"website": "string", | ||
"zoneinfo": "string" | ||
} |
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