From 035c81b957ad95d8e7d2853468884a3787b46b18 Mon Sep 17 00:00:00 2001 From: Meir Tseitlin Date: Mon, 25 Jan 2021 10:30:11 -0600 Subject: [PATCH] new: Add support for Auth0 authentication (#1934) Co-authored-by: Meir Tseitlin --- panel/auth.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/panel/auth.py b/panel/auth.py index 314b017dab..cc03addac6 100644 --- a/panel/auth.py +++ b/panel/auth.py @@ -313,6 +313,38 @@ class BitbucketLoginHandler(OAuthLoginHandler, OAuth2Mixin): _USER_KEY = 'username' +class Auth0Handler(OAuthLoginHandler, OAuth2Mixin): + + _EXTRA_AUTHORIZE_PARAMS = { + 'subdomain' + } + + _OAUTH_ACCESS_TOKEN_URL_ = 'https://{0}.auth0.com/oauth/token' + _OAUTH_AUTHORIZE_URL_ = 'https://{0}.auth0.com/authorize' + _OAUTH_USER_URL_ = 'https://{0}.auth0.com/userinfo?access_token=' + + @property + def _OAUTH_ACCESS_TOKEN_URL(self): + url = config.oauth_extra_params.get('subdomain', 'example') + return self._OAUTH_ACCESS_TOKEN_URL_.format(url) + + @property + def _OAUTH_AUTHORIZE_URL(self): + url = config.oauth_extra_params.get('subdomain', 'example') + return self._OAUTH_AUTHORIZE_URL_.format(url) + + @property + def _OAUTH_USER_URL(self): + url = config.oauth_extra_params.get('subdomain', 'example') + return self._OAUTH_USER_URL_.format(url) + + _USER_KEY = 'email' + + _EXTRA_TOKEN_PARAMS = { + 'grant_type': 'authorization_code' + } + + class GitLabLoginHandler(OAuthLoginHandler, OAuth2Mixin): _API_BASE_HEADERS = { @@ -639,6 +671,7 @@ def logout_handler(self): AUTH_PROVIDERS = { + 'auth0': Auth0Handler, 'azure': AzureAdLoginHandler, 'bitbucket': BitbucketLoginHandler, 'google': GoogleLoginHandler,