Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GenericLoginHandler for custom OAuth #2873

Merged
merged 4 commits into from
Nov 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions panel/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ async def get_authenticated_user(self, redirect_uri, client_id, state,
'redirect_uri': redirect_uri,
'client_id': client_id,
'client_secret': client_secret,
'response_type': 'code',
'extra_params': {
'state': state,
},
Expand Down Expand Up @@ -289,6 +290,33 @@ def _on_error(self, response, body=None):
raise HTTPError(500, f"{provider} authentication failed")


class GenericLoginHandler(OAuthLoginHandler, OAuth2Mixin):

_access_token_header = 'Bearer {}'

_EXTRA_TOKEN_PARAMS = {
'grant_type': 'authorization_code'
}

_SCOPE = ['openid', 'email']

@property
def _OAUTH_ACCESS_TOKEN_URL(self):
return config.oauth_extra_params['TOKEN_URL']

@property
def _OAUTH_AUTHORIZE_URL(self):
return config.oauth_extra_params['AUTHORIZE_URL']

@property
def _OAUTH_USER_URL(self):
return config.oauth_extra_params['USER_URL']

@property
def _USER_KEY(self):
return config.oauth_extra_params.get('USER_KEY', 'email')


class GithubLoginHandler(OAuthLoginHandler, OAuth2Mixin):
"""GitHub OAuth2 Authentication
To authenticate with GitHub, first register your application at
Expand All @@ -306,7 +334,6 @@ class GithubLoginHandler(OAuthLoginHandler, OAuth2Mixin):

_USER_KEY = 'login'



class BitbucketLoginHandler(OAuthLoginHandler, OAuth2Mixin):

Expand Down Expand Up @@ -585,7 +612,7 @@ def _OAUTH_USER_URL(self):

class OktaLoginHandler(OAuthIDTokenLoginHandler, OAuth2Mixin):
"""Okta OAuth2 Authentication

To authenticate with Okta you first need to set up and configure
in the Okta developer console.
"""
Expand Down Expand Up @@ -687,6 +714,7 @@ def logout_handler(self):
'auth0': Auth0Handler,
'azure': AzureAdLoginHandler,
'bitbucket': BitbucketLoginHandler,
'generic': GenericLoginHandler,
'google': GoogleLoginHandler,
'github': GithubLoginHandler,
'gitlab': GitLabLoginHandler,
Expand Down