snok / django-auth-adfs

A Django authentication backend for Microsoft ADFS and AzureAD
http://django-auth-adfs.readthedocs.io/
BSD 2-Clause "Simplified" License
270 stars 97 forks source link

Authentication of a multi-tenant Azure API #337

Closed lucasvandijck closed 3 months ago

lucasvandijck commented 3 months ago

I am trying to authenticate my Django API using an access token from Azure. The problem is that my API is multi-tenant, and the provided example only works for single tenant applications. I used to following setting to fix this: AZURE_AD_TENANT_ID = "common"

The problem now is that my JWT token contains the issuer: https://login.microsoftonline.com/<tenant-id-here>/v2.0

However, the module checks this against the issuer: https://login.microsoftonline.com/{tenantid}/v2.0 ({tenantid} is not replaced by anything I think)

How should I fix this issue?

Upvote & Fund

Fund with Polar

JonasKs commented 3 months ago

There's no true multi tenant support in this package, since it was written for ADFS back in the days.

You could override the validate access token function and use your own.
Allowing any tenant, you don't validate the issuer.
If you have a list of tenants to allow, you could provide a list iirc.

PR welcome.

You can see my multi tenant implementation (fastapi-azure-auth use Python-Jose and not pyjwt): https://github.com/Intility/fastapi-azure-auth/blob/main/fastapi_azure_auth/auth.py#L189

lucasvandijck commented 3 months ago

Seems logical, thank you for the help!