nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
25.03k stars 3.54k forks source link

MicrosoftEntraID docs in 5.0 misleading #12193

Closed rhufsky closed 2 weeks ago

rhufsky commented 2 weeks ago

What is the improvement or update you wish to see?

The docs recommend this config

import MicrosoftEntraID from "@auth/core/providers/microsoft-entra-id"

providers: [
  MicrosoftEntraID({
    clientId: env.AUTH_MICROSOFT_ENTRA_ID_ID,
    clientSecret: env.AUTH_MICROSOFT_ENTRA_ID_SECRET,
    issuer: env.AUTH_MICROSOFT_ENTRA_ID_TENANT_ID,
  }),
]

Change issuerto tenantId.

Is there any context that might help us understand?

The docs recommend this config

import MicrosoftEntraID from "@auth/core/providers/microsoft-entra-id"

providers: [
  MicrosoftEntraID({
    clientId: env.AUTH_MICROSOFT_ENTRA_ID_ID,
    clientSecret: env.AUTH_MICROSOFT_ENTRA_ID_SECRET,
    issuer: env.AUTH_MICROSOFT_ENTRA_ID_TENANT_ID,
  }),
]

internally issuer seems to be an URL. When providing tenant id here, the provider raises an exception while attempting to create an URL object out of the tenant id.

Does the docs page already exist? Please link to it.

https://authjs.dev/reference/core/providers/microsoft-entra-id

Riyooo commented 2 weeks ago

I also had trouble following the documentation and migrating to the new Microsoft Entra ID provider, thinking that the 'issuer' parameter was the 'tenantId', which caused the following error: [auth][error] TypeError: Invalid URL

'issuer' seems instead to be an URL in the following format: https://login.microsoftonline.com/[tenantID]/v2.0 So finally what I did was changing my .env.local file and adding the following entry which seems to work:

# the issuer URL
AUTH_MICROSOFT_ENTRA_ID_ISSUER="https://login.microsoftonline.com/$AUTH_MICROSOFT_ENTRA_ID_TENANT_ID/v2.0"

Maybe could the docs be more specific about this parameter?

rhufsky commented 2 weeks ago

You are right, this works, see also https://github.com/nextauthjs/next-auth/issues/12195