sources/oauth: add OIDC client
This commit is contained in:
parent
f58ee7fb52
commit
13a20478fd
|
@ -12,4 +12,5 @@ PASSBOOK_SOURCES_OAUTH_TYPES = [
|
|||
"passbook.sources.oauth.types.reddit",
|
||||
"passbook.sources.oauth.types.twitter",
|
||||
"passbook.sources.oauth.types.azure_ad",
|
||||
"passbook.sources.oauth.types.oidc",
|
||||
]
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
"""OpenID Connect OAuth Views"""
|
||||
from typing import Dict
|
||||
|
||||
from passbook.sources.oauth.models import OAuthSource
|
||||
from passbook.sources.oauth.types.manager import MANAGER, RequestKind
|
||||
from passbook.sources.oauth.utils import user_get_or_create
|
||||
from passbook.sources.oauth.views.core import OAuthCallback, OAuthRedirect
|
||||
|
||||
|
||||
@MANAGER.source(kind=RequestKind.redirect, name="OpenID Connect")
|
||||
class OpenIDConnectOAuthRedirect(OAuthRedirect):
|
||||
"""OpenIDConnect OAuth2 Redirect"""
|
||||
|
||||
def get_additional_parameters(self, source: OAuthSource):
|
||||
return {
|
||||
"scope": "openid email",
|
||||
}
|
||||
|
||||
|
||||
@MANAGER.source(kind=RequestKind.callback, name="OpenID Connect")
|
||||
class OpenIDConnectOAuth2Callback(OAuthCallback):
|
||||
"""OpenIDConnect OAuth2 Callback"""
|
||||
|
||||
def get_user_id(self, source: OAuthSource, info: Dict[str, str]):
|
||||
return info.get("sub")
|
||||
|
||||
def get_or_create_user(self, source: OAuthSource, access, info: Dict[str, str]):
|
||||
user_data = {
|
||||
"username": info.get("username"),
|
||||
"email": info.get("email"),
|
||||
"name": info.get("username"),
|
||||
"password": None,
|
||||
}
|
||||
return user_get_or_create(**user_data)
|
|
@ -0,0 +1 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24" version="1.1"><path d="M14 3l-3 2v15c-4.059-.531-6-2.68-6-5 0-2.18 1.781-3.445 5-4.031V9c-4.95.629-8 2.754-8 6 0 3.383 3.102 6.512 9 7l3-2zm1 6v2a9.514 9.514 0 0 1 2.75 1.031l-1.656.938L22 14l-.313-4.156-1.625.875C18.684 9.883 16.945 9.289 15 9z" id="surface1"/><metadata><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:dc="http://purl.org/dc/elements/1.1/"><rdf:Description about="https://iconscout.com/legal#licenses" dc:title="openid" dc:description="openid" dc:publisher="Iconscout" dc:date="2018-06-22" dc:format="image/svg+xml" dc:language="en"><dc:creator><rdf:Bag><rdf:li>Icons8</rdf:li></rdf:Bag></dc:creator></rdf:Description></rdf:RDF></metadata></svg>
|
After Width: | Height: | Size: 878 B |
Reference in New Issue