import type { OAuthConfig , OAuthUserConfig } from "." ; export interface AzureADProfile { sub : string ; nicname : string ; email : string ; picture : string ; } export default function AzureAD < P extends Record < string , any > = AzureADProfile > ( options ) { const tenant = options . tenantId ?? "common" ; const profilePhotoSize = options . profilePhotoSize ?? 48 ; return { id : "azure-ad" , name : "Azure Active Directory" , type : "oauth" , wellKnown : `https://login.microsoftonline.com/${ tenant }/v2.0/.well-known/openid-configuration` , authorization : { params : { scope : "openid profile email" , } , } , async profile ( profile , tokens ) { const profilePicture = await fetch ( `https://graph.microsoft.com/v1.0/me/photos/${ profilePhotoSize }x${ profilePhotoSize }/$value` , { headers : { Authorization : `Bearer ${ tokens . access_token }` , } , } ) ; const pictureBuffer = await profilePicture . arrayBuffer ( ) ; const pictureBase64 = Buffer . from ( pictureBuffer ) . toString ( "base64" ) ; return { id : profile . sub , name : profile . name , email : profile . email , image : `data:image/jpeg;base64, ${ pictureBase64 }` , } ; } , options , } ; }