pennersr / django-allauth

Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.
https://allauth.org
MIT License
9.41k stars 3.01k forks source link

Azure AD redirect uri swapping protocols #3666

Closed StevenMapes closed 6 months ago

StevenMapes commented 6 months ago

I'm a new user to the project and must confess to having struggled to find some documentation relating to integrating Azure AD as the auth provider but I've muddled through thanks to this S/O thread https://stackoverflow.com/questions/73885989/django-allauth-azure-ad-configurations but I'm not hitting an issue where the redirect url that is being sent to Microsoft has incorrectly changed the protocol from https to http which is then triggering an error during the sign in process due to the redirect URI not matching the URI configured for the application

Within Azure I have set the redirect URI to https://example.mapestech.co.uk/oauth/accounts/microsoft/login/callback/ but when I go through the login sets and track the requests and response from the Django project I can see that the POST to https://example.mapestech.co.uk/oauth/accounts/microsoft/login/?process=login is is resulting in HTTP 302 redirect to:

https://login.microsoftonline.com/14acee09-b9f7-4967-b018-4311c727ae15/oauth2/v2.0/authorize?client_id=REDACTED-FAKE-FAKE-FAKE-REDACTED&redirect_uri=http%3A%2F%2Fexample.mapestech.co.uk%2Foauth%2Faccounts%2Fmicrosoft%2Flogin%2Fcallback%2F&scope=User.Read&response_type=code&state=STUFF

Is there a setting I've missed to force the correct protocol to be send in the redirect uri to Microsoft as I don't really want to have to enable a http redirect endpoint to the applications redirect url in azure

StevenMapes commented 6 months ago

And right after posting I found the answer., I need to set ACCOUNT_DEFAULT_HTTP_PROTOCOL to "https"

pennersr commented 6 months ago

Are you running behind a proxy, if so, you might want to look into this instead: https://docs.djangoproject.com/en/5.0/ref/settings/#secure-proxy-ssl-header