Skip to content

Instantly share code, notes, and snippets.

@maljukan
Last active January 26, 2024 14:35
Show Gist options
  • Save maljukan/bd8d220500158a11706cd4756890b07b to your computer and use it in GitHub Desktop.
Save maljukan/bd8d220500158a11706cd4756890b07b to your computer and use it in GitHub Desktop.
Django BaseOAuth2 workaround for setting the redirect_uri to localhost
class AzureADOAuth2v2(BaseOAuth2):
# Workaround for setting the redirect_uri to localhost.
# Host is set in proxy server.py and redirect_uri takes the request host value
def get_redirect_uri(self, state=None):
"""Build redirect with redirect_state parameter."""
uri = self.redirect_uri
if self.REDIRECT_STATE and state:
uri = self.url_add_parameters(uri, {"redirect_state": state})
if settings.DEBUG:
return uri.replace('127.0.0.1', 'localhost')
return uri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment