8000 Add OAuth provider (Auth0) logout url to error template by dalthviz · Pull Request #8036 · holoviz/panel · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
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
Add OAuth provider (Auth0) logout url to error template
  • Loading branch information
dalthviz committed Jul 9, 2025
commit ce981f8e83f6ad4ddb600d439e4ef5fc13dc7f5b
4 changes: 4 additions & 0 deletions panel/_templates/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
.error-message {
max-width: 80%;
padding-bottom: 10%;
text-align: center;
}
{% block extra_style %}{% endblock %}
</style>
Expand All @@ -83,6 +84,9 @@
<section class="error-message">
{% block content %}
<h3>{{ error_msg }}</h3>
{% if oauth_logout_link %}
<a href="{{ oauth_logout_link }}">Logout</a>
{% endif %}
{% endblock %}
</section>
</div>
Expand Down
43 changes: 42 additions & 1 deletion panel/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ def write_error(self, status_code, **kwargs):
title='Panel: Authentication Error',
error_type='Authentication Error',
error=error,
error_msg=error_msg
error_msg=error_msg,
oauth_logout_link=self._OAUTH_LOGOUT_URL,
))


Expand All @@ -516,6 +517,10 @@ def _OAUTH_AUTHORIZE_URL(self):
def _OAUTH_USER_URL(self):
return config.oauth_extra_params.get('USER_URL', os.environ.get('PANEL_OAUTH_USER_URL'))

@property
def _OAUTH_LOGOUT_URL(self):
return config.oauth_extra_params.get('LOGOUT_URL', os.environ.get('PANEL_OAUTH_LOGOUT_URL'))

@property
def _USER_KEY(self):
return config.oauth_extra_params.get('USER_KEY', os.environ.get('PANEL_USER_KEY', 'email'))
Expand Down Expand Up @@ -609,6 +614,7 @@ class GithubLoginHandler(OAuthLoginHandler):
_OAUTH_ACCESS_TOKEN_URL = 'https://github.com/login/oauth/access_token'
_OAUTH_AUTHORIZE_URL = 'https://github.com/login/oauth/authorize'
_OAUTH_USER_URL = 'https://api.github.com/user'
_OAUTH_LOGOUT_URL = ''

_access_token_header = 'token {}'

Expand All @@ -624,6 +630,7 @@ class BitbucketLoginHandler(OAuthLoginHandler):
_OAUTH_ACCESS_TOKEN_URL = "https://bitbucket.org/site/oauth2/access_token"
_OAUTH_AUTHORIZE_URL = "https://bitbucket.org/site/oauth2/authorize"
_OAUTH_USER_URL = "https://api.bitbucket.org/2.0/user?access_token="
_OAUTH_LOGOUT_URL = ""

_USER_KEY = 'username'

Expand All @@ -635,6 +642,7 @@ class Auth0Handler(OAuthLoginHandler):
_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'
_OAUTH_LOGOUT_URL_ = 'https://{0}.auth0.com/v2/logout?client_id={1}&returnTo={2}'

_USER_KEY = 'email'

Expand All @@ -653,6 +661,12 @@ def _OAUTH_USER_URL(self):
url = config.oauth_extra_params.get('subdomain', 'example')
return self._OAUTH_USER_URL_.format(url)

@property
def _OAUTH_LOGOUT_URL(self):
subdomain = config.oauth_extra_params.get('subdomain', 'example')
client_id = config.oauth_key
return_to = f'{self.request.protocol}://{self.request.host}/logout'
return self._OAUTH_LOGOUT_URL_.format(subdomain, client_id, return_to)


class GitLabLoginHandler(OAuthLoginHandler):
Expand All @@ -668,6 +682,7 @@ class GitLabLoginHandler(OAuthLoginHandler):
_OAUTH_ACCESS_TOKEN_URL_ = 'https://{0}/oauth/token'
_OAUTH_AUTHORIZE_URL_ = 'https://{0}/oauth/authorize'
_OAUTH_USER_URL_ = 'https://{0}/api/v4/user'
_OAUTH_LOGOUT_URL_ = ''

_access_token_header = 'Bearer {}'

Expand All @@ -688,6 +703,10 @@ def _OAUTH_USER_URL(self):
url = config.oauth_extra_params.get('url', 'gitlab.com')
return self._OAUTH_USER_URL_.format(url)

@property
def _OAUTH_LOGOUT_URL(self):
return self._OAUTH_LOGOUT_URL_.format(**config.oauth_extra_params)


class AzureAdLoginHandler(OAuthLoginHandler):

Expand All @@ -699,6 +718,7 @@ class AzureAdLoginHandler(OAuthLoginHandler):
_OAUTH_ACCESS_TOKEN_URL_ = 'https://login.microsoftonline.com/{tenant}/oauth2/token'
_OAUTH_AUTHORIZE_URL_ = 'https://login.microsoftonline.com/{tenant}/oauth2/authorize'
_OAUTH_USER_URL_ = ''
_OAUTH_LOGOUT_URL_ = ''

_USER_KEY = 'unique_name'

Expand All @@ -716,6 +736,10 @@ def _OAUTH_AUTHORIZE_URL(self):
def _OAUTH_USER_URL(self):
return self._OAUTH_USER_URL_.format(**config.oauth_extra_params)

@property
def _OAUTH_LOGOUT_URL(self):
return self._OAUTH_LOGOUT_URL_.format(**config.oauth_extra_params)


class AzureAdV2LoginHandler(OAuthLoginHandler):

Expand All @@ -727,6 +751,7 @@ class AzureAdV2LoginHandler(OAuthLoginHandler):
_OAUTH_ACCESS_TOKEN_URL_ = 'https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token'
_OAUTH_AUTHORIZE_URL_ = 'https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize'
_OAUTH_USER_URL_ = ''
_OAUTH_LOGOUT_URL_ = ''

_USER_KEY = 'email'

Expand All @@ -744,6 +769,10 @@ def _OAUTH_AUTHORIZE_URL(self):
def _OAUTH_USER_URL(self):
return self._OAUTH_USER_URL_.format(**config.oauth_extra_params)

@property
def _OAUTH_LOGOUT_URL(self):
return self._OAUTH_LOGOUT_URL_.format(**config.oauth_extra_params)


class OktaLoginHandler(OAuthLoginHandler):
"""Okta OAuth2 Authentication
Expand All @@ -763,6 +792,8 @@ class OktaLoginHandler(OAuthLoginHandler):
_OAUTH_AUTHORIZE_URL__ = 'https://{0}/oauth2/v1/authorize'
_OAUTH_USER_URL_ = 'https://{0}/oauth2/{1}/v1/userinfo?access_token='
_OAUTH_USER_URL__ = 'https://{0}/oauth2/v1/userinfo?access_token='
_OAUTH_LOGOUT_URL_ = ''
_OAUTH_LOGOUT_URL__ = ''

_USER_KEY = 'email'

Expand Down Expand Up @@ -793,6 +824,15 @@ def _OAUTH_USER_URL(self):
else:
return self._OAUTH_USER_URL__.format(url, server)

@property
def _OAUTH_LOGOUT_URL(self):
url = config.oauth_extra_params.get('url', 'okta.com')
server = config.oauth_extra_params.get('server', 'default')
if server:
return self._OAUTH_LOGOUT_URL_.format(url, server)
else:
return self._OAUTH_LOGOUT_URL__.format(url, server)


class GoogleLoginHandler(OAuthLoginHandler):

Expand All @@ -803,6 +843,7 @@ class GoogleLoginHandler(OAuthLoginHandler):
_OAUTH_AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/v2/auth"
_OAUTH_ACCESS_TOKEN_URL = "https://accounts.google.com/o/oauth2/token"
_USER_KEY = 'email'
_OAUTH_LOGOUT_URL = ''


class BasicLoginHandler(RequestHandler):
Expand Down
Loading
0