The Django integration in this library appears to stash an authentication token from MS Identity API into the Django session:
|
self._save_user_into_session(result["id_token_claims"]) |
|
self._save_cache(cache) |
|
flow = self._session.pop(self._AUTH_FLOW, {}) |
|
return {"next_link": flow.get(self.__NEXT_LINK)} |
And then an app is expected to pull that using the context parameter, for example:
https://github.com/Azure-Samples/ms-identity-python-webapp-django/blob/9a277ede91f68293e1d95a45bfc50b1fb191d06d/mysite/views.py#L12-L19
In that snippet, settings.AUTH is identity.django.Auth.
I don't think this library implements Django authentication correctly, which leads to significant limitations:
-
MS Identity sessions are completely separate to normal Django user sessions – so there's no way to use these sessions in Django Admin, or apply permissions of any kind.
-
There's no way to reference an MS Identity user as a foreign key (a limitation noted in Microsoft's other samples)
Using Django's "writing an authentication backend" doc and Django's REMOTE_USER how-to as a similarly shaped example, I'd expect:
After spending a lot of time trying to research Entra authentication integration, I also note this is not even the complete solution – you'd ideally want a SCIM implementation running in Django to allow Entra to provision users and groups, so that you're not waiting on users to log in to update things, and can deactivate accounts. 😄
The Django integration in this library appears to stash an authentication token from MS Identity API into the Django session:
identity/identity/web.py
Lines 217 to 220 in 3d705f0
And then an app is expected to pull that using the
contextparameter, for example:https://github.com/Azure-Samples/ms-identity-python-webapp-django/blob/9a277ede91f68293e1d95a45bfc50b1fb191d06d/mysite/views.py#L12-L19
In that snippet,
settings.AUTHisidentity.django.Auth.I don't think this library implements Django authentication correctly, which leads to significant limitations:
MS Identity sessions are completely separate to normal Django user sessions – so there's no way to use these sessions in Django Admin, or apply permissions of any kind.
There's no way to reference an MS Identity user as a foreign key (a limitation noted in Microsoft's other samples)
Using Django's "writing an authentication backend" doc and Django's
REMOTE_USERhow-to as a similarly shaped example, I'd expect:an extended or replacement
Usermodel, which is keyed on theoidattributea class which can be referenced in
AUTHENTICATION_BACKENDS, that consumes an MS Identity-issued JWT and creates DjangoUsermodels as appropriate.After spending a lot of time trying to research Entra authentication integration, I also note this is not even the complete solution – you'd ideally want a SCIM implementation running in Django to allow Entra to provision users and groups, so that you're not waiting on users to log in to update things, and can deactivate accounts. 😄