Last active
August 3, 2020 17:58
-
-
Save danizen/e5adf44c53cb6c607a7dc6b747aa9b80 to your computer and use it in GitHub Desktop.
Excerpt of logout flow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LogoutMixin: | |
def logout_params(self, next_page): | |
# Backend should provide this | |
return { | |
'logout_uri': next_page | |
} | |
def logout_baseurl(self): | |
# Backend should provide this | |
return '/logout' | |
def logout_url(self, next_page): | |
params = self.logout_params(next_page) | |
return '{0}?{1}'.format(self.logout_baseurl(), urlencode(params)) | |
class CognitoNIH(CognitoProviderOAuth2, LogoutMixin): | |
# ... excerpt from class ... | |
def logout_params(self, next_page): | |
# Cognito's Logout ENDPOINT does not logout of NIH Login. | |
# So, we rewrite the next_page URL to be NIH login's with | |
# AppReturnUrl set to the next_page. | |
client_id, client_secret = self.get_key_and_secret() | |
nih_logout_url = self.DOMAIN_TO_NIHLOGOUT.get(self.user_pool_domain()) | |
if nih_logout_url: | |
next_page = '{}?AppReturnUrl={}'.format(nih_logout_url, next_page) | |
return { | |
'client_id': client_id, | |
'logout_uri': next_page | |
} | |
def logout_baseurl(self): | |
return '{}/logout'.format(self.user_pool_domain()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LogoutCBV(LogoutView): | |
# ... some details omitted ... | |
def dispatch(self, request, *args, **kwargs): | |
backend = self.get_backend() | |
auth_logout(request) | |
if backend and hasattr(backend, 'logout_url'): | |
next_page = self.get_next_page() | |
if not next_page: | |
LOG.info('No LOGOUT_REDIRECT_URL or next: falling back to /') | |
next_page = '/' | |
if next_page.startswith('/'): | |
next_page = request.build_absolute_uri(next_page) | |
logout_url = backend.logout_url(next_page) | |
return HttpResponseRedirect(logout_url) | |
return super().dispatch(request, *args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment