Skip to content

Commit

Permalink
update to OIDC
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Oct 6, 2024
1 parent 17ae956 commit fcb5853
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions packages/core/src/providers/microsoft-entra-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @module providers/microsoft-entra-id
*/
import type { OAuthConfig, OAuthUserConfig } from "./index.js"
import type { OIDCConfig, OIDCUserConfig } from "./index.js"

export interface MicrosoftEntraIDProfile extends Record<string, any> {
sub: string
Expand All @@ -17,18 +17,6 @@ export interface MicrosoftEntraIDProfile extends Record<string, any> {
picture: string
}

export type MicrosoftEntraIDOptions<P extends MicrosoftEntraIDProfile> =
OAuthUserConfig<P> & {
/**
* https://learn.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-1.0&tabs=http#examples
*
* @default 48
*/
profilePhotoSize?: 48 | 64 | 96 | 120 | 240 | 360 | 432 | 504 | 648
/** @default "common" */
tenantId?: string
}

/**
*
* Add Microsoft Entra ID login to your page.
Expand Down Expand Up @@ -111,8 +99,8 @@ export type MicrosoftEntraIDOptions<P extends MicrosoftEntraIDProfile> =
*
* ### Notes
*
* By default, Auth.js assumes that the MicrosoftEntra provider is
* based on the [OAuth 2](https://www.rfc-editor.org/rfc/rfc6749.html) specification.
* By default, Auth.js assumes that the Microsoft Entra ID provider is
* based on the [Open ID Connect](https://openid.net/specs/openid-connect-core-1_0.html) specification.
*
* :::tip
*
Expand All @@ -131,21 +119,25 @@ export type MicrosoftEntraIDOptions<P extends MicrosoftEntraIDProfile> =
*
* :::
*/
export default function MicrosoftEntraID<P extends MicrosoftEntraIDProfile>(
options: MicrosoftEntraIDOptions<P>
): OAuthConfig<P> {
const { tenantId = "common", profilePhotoSize = 48, ...rest } = options
rest.issuer ??= `https://login.microsoftonline.com/${tenantId}/v2.0`
export default function MicrosoftEntraID(
config: OIDCUserConfig<MicrosoftEntraIDProfile> & {
/**
* https://learn.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-1.0&tabs=http#examples
*
* @default 48
*/
profilePhotoSize?: 48 | 64 | 96 | 120 | 240 | 360 | 432 | 504 | 648
/** @default "common" */
tenantId?: string
}
): OIDCConfig<MicrosoftEntraIDProfile> {
const { profilePhotoSize = 48, tenantId = "common", ...rest } = config
return {
id: "microsoft-entra-id",
name: "Microsoft Entra ID",
type: "oidc",
wellKnown: `${rest.issuer}/.well-known/openid-configuration?appid=${options.clientId}`,
authorization: {
params: {
scope: "openid profile email User.Read",
},
},
wellKnown: `${rest.issuer}/.well-known/openid-configuration?appid=${config.clientId}`,
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(
Expand Down

0 comments on commit fcb5853

Please sign in to comment.