Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/core/src/providers/microsoft-entra-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,17 @@ export default function MicrosoftEntraID(

config.issuer ??= "https://login.microsoftonline.com/common/v2.0"

// https://authjs.dev/guides/corporate-proxy
const fetchFunction = config[customFetch] || fetch;

return {
id: "microsoft-entra-id",
name: "Microsoft Entra ID",
type: "oidc",
authorization: { params: { scope: "openid profile email User.Read" } },
async profile(profile, tokens) {
// https://learn.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-1.0&tabs=http#examples
const response = await fetch(
const response = await fetchFunction(
`https://graph.microsoft.com/v1.0/me/photos/${profilePhotoSize}x${profilePhotoSize}/$value`,
{ headers: { Authorization: `Bearer ${tokens.access_token}` } }
)
Expand Down Expand Up @@ -142,14 +145,14 @@ export default function MicrosoftEntraID(
async [customFetch](...args) {
const url = new URL(args[0] instanceof Request ? args[0].url : args[0])
if (url.pathname.endsWith(".well-known/openid-configuration")) {
const response = await fetch(...args)
const response = await fetchFunction(...args)
const json = await response.clone().json()
const tenantRe = /microsoftonline\.com\/(\w+)\/v2\.0/
const tenantId = config.issuer?.match(tenantRe)?.[1] ?? "common"
const issuer = json.issuer.replace("{tenantid}", tenantId)
return Response.json({ ...json, issuer })
}
return fetch(...args)
return fetchFunction(...args)
},
[conformInternal]: true,
options: config,
Expand Down