sources/oauth: add OIDC client

This commit is contained in:
Jens Langhammer
2020-05-19 21:53:46 +02:00
parent f58ee7fb52
commit 13a20478fd
3 changed files with 36 additions and 0 deletions

View File

@ -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",
]

View File

@ -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)