authentik.sources.oauth.types.patreon
Patreon OAuth Views
1"""Patreon OAuth Views""" 2 3from typing import Any 4 5from authentik.sources.oauth.clients.oauth2 import UserprofileHeaderAuthClient 6from authentik.sources.oauth.models import AuthorizationCodeAuthMethod, OAuthSource 7from authentik.sources.oauth.types.registry import SourceType, registry 8from authentik.sources.oauth.views.callback import OAuthCallback 9from authentik.sources.oauth.views.redirect import OAuthRedirect 10 11 12class PatreonOAuthRedirect(OAuthRedirect): 13 """Patreon OAuth2 Redirect""" 14 15 def get_additional_parameters(self, source: OAuthSource): # pragma: no cover 16 # https://docs.patreon.com/#scopes 17 return { 18 "scope": ["identity", "identity[email]"], 19 } 20 21 22class PatreonOAuthCallback(OAuthCallback): 23 """Patreon OAuth2 Callback""" 24 25 client_class: UserprofileHeaderAuthClient 26 27 def get_user_id(self, info: dict[str, str]) -> str: 28 return info.get("data", {}).get("id") 29 30 31@registry.register() 32class PatreonType(SourceType): 33 """OpenIDConnect Type definition""" 34 35 callback_view = PatreonOAuthCallback 36 redirect_view = PatreonOAuthRedirect 37 verbose_name = "Patreon" 38 name = "patreon" 39 40 authorization_url = "https://www.patreon.com/oauth2/authorize" 41 access_token_url = "https://www.patreon.com/api/oauth2/token" # nosec 42 profile_url = "https://www.patreon.com/api/oauth2/api/current_user" 43 44 authorization_code_auth_method = AuthorizationCodeAuthMethod.POST_BODY 45 46 def get_base_user_properties(self, info: dict[str, Any], **kwargs) -> dict[str, Any]: 47 return { 48 "username": info.get("data", {}).get("attributes", {}).get("vanity"), 49 "email": info.get("data", {}).get("attributes", {}).get("email"), 50 "name": info.get("data", {}).get("attributes", {}).get("full_name"), 51 }
13class PatreonOAuthRedirect(OAuthRedirect): 14 """Patreon OAuth2 Redirect""" 15 16 def get_additional_parameters(self, source: OAuthSource): # pragma: no cover 17 # https://docs.patreon.com/#scopes 18 return { 19 "scope": ["identity", "identity[email]"], 20 }
Patreon OAuth2 Redirect
23class PatreonOAuthCallback(OAuthCallback): 24 """Patreon OAuth2 Callback""" 25 26 client_class: UserprofileHeaderAuthClient 27 28 def get_user_id(self, info: dict[str, str]) -> str: 29 return info.get("data", {}).get("id")
Patreon OAuth2 Callback
32@registry.register() 33class PatreonType(SourceType): 34 """OpenIDConnect Type definition""" 35 36 callback_view = PatreonOAuthCallback 37 redirect_view = PatreonOAuthRedirect 38 verbose_name = "Patreon" 39 name = "patreon" 40 41 authorization_url = "https://www.patreon.com/oauth2/authorize" 42 access_token_url = "https://www.patreon.com/api/oauth2/token" # nosec 43 profile_url = "https://www.patreon.com/api/oauth2/api/current_user" 44 45 authorization_code_auth_method = AuthorizationCodeAuthMethod.POST_BODY 46 47 def get_base_user_properties(self, info: dict[str, Any], **kwargs) -> dict[str, Any]: 48 return { 49 "username": info.get("data", {}).get("attributes", {}).get("vanity"), 50 "email": info.get("data", {}).get("attributes", {}).get("email"), 51 "name": info.get("data", {}).get("attributes", {}).get("full_name"), 52 }
OpenIDConnect Type definition
callback_view =
<class 'PatreonOAuthCallback'>
redirect_view =
<class 'PatreonOAuthRedirect'>
access_token_url =
'https://wwwauthentik.sources.oauth.types.patreon.com/api/oauth2/token'
profile_url =
'https://wwwauthentik.sources.oauth.types.patreon.com/api/oauth2/api/current_user'
def
get_base_user_properties(self, info: dict[str, typing.Any], **kwargs) -> dict[str, typing.Any]:
47 def get_base_user_properties(self, info: dict[str, Any], **kwargs) -> dict[str, Any]: 48 return { 49 "username": info.get("data", {}).get("attributes", {}).get("vanity"), 50 "email": info.get("data", {}).get("attributes", {}).get("email"), 51 "name": info.get("data", {}).get("attributes", {}).get("full_name"), 52 }
Get base user properties for enrollment/update