Skip to content

Commit 58a98b6

Browse files
fix(providers): resize default AzureAD profile picture (#2910)
* Update azure-ad.js * fix: default azure AD profile photo size Co-authored-by: ndom91 <yo@ndo.dev>
1 parent 129d161 commit 58a98b6

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

app/pages/api/auth/[...nextauth].ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export default NextAuth({
142142
clientId: process.env.AZURE_AD_CLIENT_ID,
143143
clientSecret: process.env.AZURE_AD_CLIENT_SECRET,
144144
tenantId: process.env.AZURE_AD_TENANT_ID,
145+
profilePhotoSize: 48,
145146
}),
146147
SpotifyProvider({
147148
clientId: process.env.SPOTIFY_ID,

src/providers/azure-ad-b2c.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ export interface AzureB2CProfile {
1919

2020
export default function AzureADB2C<
2121
P extends Record<string, any> = AzureB2CProfile
22-
>(options: OAuthUserConfig<P> & { primaryUserFlow: string }): OAuthConfig<P> {
22+
>(
23+
options: OAuthUserConfig<P> & {
24+
primaryUserFlow: string
25+
tenantId: string
26+
}
27+
): OAuthConfig<P> {
2328
const { tenantId, primaryUserFlow } = options
2429
return {
2530
id: "azure-ad-b2c",

src/providers/azure-ad.js renamed to src/providers/azure-ad.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
/** @type {import(".").OAuthProvider} */
2-
export default function AzureAD(options) {
1+
import { OAuthConfig, OAuthUserConfig } from "./oauth"
2+
3+
export interface AzureADProfile {
4+
sub: string
5+
nicname: string
6+
email: string
7+
picture: string
8+
}
9+
10+
export default function AzureAD<P extends Record<string, any> = AzureADProfile>(
11+
options: OAuthUserConfig<P> & {
12+
/**
13+
* https://docs.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-1.0#examples
14+
* @default 48
15+
*/
16+
profilePhotoSize?: 48 | 64 | 96 | 120 | 240 | 360 | 432 | 504 | 648
17+
/** @default "common" */
18+
tenantId?: string
19+
}
20+
): OAuthConfig<P> {
321
const tenant = options.tenantId ?? "common"
22+
const profilePhotoSize = options.profilePhotoSize ?? 48
423

524
return {
625
id: "azure-ad",
@@ -15,7 +34,7 @@ export default function AzureAD(options) {
1534
async profile(profile, tokens) {
1635
// https://docs.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-1.0#examples
1736
const profilePicture = await fetch(
18-
"https://graph.microsoft.com/v1.0/me/photo/$value",
37+
`https://graph.microsoft.com/v1.0/me/photos/${profilePhotoSize}x${profilePhotoSize}/$value`,
1938
{
2039
headers: {
2140
Authorization: `Bearer ${tokens.access_token}`,

src/providers/oauth.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ export interface OAuthConfig<P> extends CommonProviderOptions, PartialIssuer {
130130
region?: string
131131
// TODO: only allow for some
132132
issuer?: string
133-
// TODO: only allow for Azure Active Directory B2C and FusionAuth
134-
tenantId?: string
135133
/**
136134
* The options provided by the user.
137135
* We will perform a deep-merge of these values

0 commit comments

Comments
 (0)