Skip to content

Commit

Permalink
fix(providers): resize default AzureAD profile picture (#2910)
Browse files Browse the repository at this point in the history
* Update azure-ad.js

* fix: default azure AD profile photo size

Co-authored-by: ndom91 <yo@ndo.dev>
  • Loading branch information
balazsorban44 and ndom91 authored Oct 10, 2021
1 parent 129d161 commit 58a98b6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export default NextAuth({
clientId: process.env.AZURE_AD_CLIENT_ID,
clientSecret: process.env.AZURE_AD_CLIENT_SECRET,
tenantId: process.env.AZURE_AD_TENANT_ID,
profilePhotoSize: 48,
}),
SpotifyProvider({
clientId: process.env.SPOTIFY_ID,
Expand Down
7 changes: 6 additions & 1 deletion src/providers/azure-ad-b2c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ export interface AzureB2CProfile {

export default function AzureADB2C<
P extends Record<string, any> = AzureB2CProfile
>(options: OAuthUserConfig<P> & { primaryUserFlow: string }): OAuthConfig<P> {
>(
options: OAuthUserConfig<P> & {
primaryUserFlow: string
tenantId: string
}
): OAuthConfig<P> {
const { tenantId, primaryUserFlow } = options
return {
id: "azure-ad-b2c",
Expand Down
25 changes: 22 additions & 3 deletions src/providers/azure-ad.js → src/providers/azure-ad.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
/** @type {import(".").OAuthProvider} */
export default function AzureAD(options) {
import { OAuthConfig, OAuthUserConfig } from "./oauth"

export interface AzureADProfile {
sub: string
nicname: string
email: string
picture: string
}

export default function AzureAD<P extends Record<string, any> = AzureADProfile>(
options: OAuthUserConfig<P> & {
/**
* https://docs.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-1.0#examples
* @default 48
*/
profilePhotoSize?: 48 | 64 | 96 | 120 | 240 | 360 | 432 | 504 | 648
/** @default "common" */
tenantId?: string
}
): OAuthConfig<P> {
const tenant = options.tenantId ?? "common"
const profilePhotoSize = options.profilePhotoSize ?? 48

return {
id: "azure-ad",
Expand All @@ -15,7 +34,7 @@ export default function AzureAD(options) {
async profile(profile, tokens) {
// https://docs.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-1.0#examples
const profilePicture = await fetch(
"https://graph.microsoft.com/v1.0/me/photo/$value",
`https://graph.microsoft.com/v1.0/me/photos/${profilePhotoSize}x${profilePhotoSize}/$value`,
{
headers: {
Authorization: `Bearer ${tokens.access_token}`,
Expand Down
2 changes: 0 additions & 2 deletions src/providers/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ export interface OAuthConfig<P> extends CommonProviderOptions, PartialIssuer {
region?: string
// TODO: only allow for some
issuer?: string
// TODO: only allow for Azure Active Directory B2C and FusionAuth
tenantId?: string
/**
* The options provided by the user.
* We will perform a deep-merge of these values
Expand Down

0 comments on commit 58a98b6

Please sign in to comment.