0

In my Django web application, I need to enable SSO - single tenant - Internal to the organization.

Based on ref tutorial: link I was able to copy-paste required code snippets in views.py, urls.py.

I also created an oauth_settings.yml file-

app_id: {app id}
app_secret: {app secret}
redirect: "http://localhost:8000/callback"
scopes:
    - user.read
authority: "https://login.microsoftonline.com/{tenant}"

Yet every time after I submit the O365 credentials, I am facing the same /callback error :-

enter image description here

I have identified the issue to be in 'auth_flow' variable which holds entire flow dict. data which is reflected earlier, but fails to be saved in the request.session.

What might the issue be here?

2
  • Have you configured this redirect url in Azure? Commented Feb 2, 2021 at 7:59
  • Yes redirect uri is set as: localhost:8000/callback in Azure AD portal Commented Feb 2, 2021 at 8:02

2 Answers 2

1

According to my test, when we were browsing to http://127.0.0.1:8000 instead of http://localhost:8000, we got the error. Because the browser does not store session and set cookie when using IP address. So please use http://localhost:8000. to access project when you develop the project on your local machine. For more details, please refer to the Github issue

use IP adreee enter image description here

use localhost enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

The correct key to extract the 'timeZone' is missing in the function def store_user().

Go to the file auth_helper.py and replace the function store_user() with the following:

def store_user(request, user):
  try:
    request.session['user'] = {
      'is_authenticated': True,
      'name': user['displayName'],
      'email': user['mail'] if (user['mail'] != None) else user['userPrincipalName'],
      'timeZone': user['mailboxSettings']['automaticRepliesSetting']['scheduledStartDateTime']['timeZone'] if (user['mailboxSettings']['automaticRepliesSetting']['scheduledStartDateTime']['timeZone'] != None) else 'UTC'
    }
  except Exception as e:
    print(e)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.