I'm using the library django-microsoft-authentication.
The application for microsoft was created, all the codes were received by me.
I did everything according to the documentation.
MICROSOFT = {
"app_id": "<my app id>",
"app_secret": "my app secret id",
"redirect": "http://localhost:8000",
"scopes": ["user.read"],
"authority": "https://login.microsoftonline.com/common",
"valid_email_domains": ["<list_of_valid_domains>"],
"logout_uri": "http://localhost:8000/admin/logout"
}
Add 'microsoft_authentication' to INSTALLED_APPS
LOGIN_URL = "/microsoft_authentication/login"
LOGIN_REDIRECT_URL = "/admin"
and urls.py
from django.urls import path, include
urlpatterns = [
.....
path('microsoft_authentication/', include('microsoft_authentication.urls'))
]
And everything goes well, and without errors. I authenticate and get returned to the home page. But there is no new user in the admin area. Or I need to do create a new user manually? Or is callback not working?
In my address bar I get some this: http://localhost:8000/?code=0.Awfwjhey79kyt4fe..........feky5hmj (random code). I understand that this is some kind of user token grant.
According to the documentation, I checked the decorator @microsoft_login_required(), and it working when I was logged in, and it did not work when I was NOT logged in. So everything is going well. But I only get the code=..... above. But I don't see the user anywhere.
How do I get a user? How do I create and save a user? Please, any help will help me.
The README on GitHub for this project shows two more items for your
settings.pyfile:In my experience, the default values for both are actually
Falseeven though the documentation saysTrue. I was unable to create new users automatically until I addedMICROSOFT_CREATE_NEW_DJANGO_USER=True.In general, I would set
MICROSOFT_NEW_DJANGO_USER_IS_STAFFtoFalseand update later in the admin section once you know that the right user has logged in.