updated MS get email method

This commit is contained in:
Zai Shi 2024-03-05 13:02:19 +08:00
parent a0781f1e44
commit 630a67bd56

View File

@ -26,8 +26,11 @@ export class MicrosoftProvider extends OAuthBaseProvider {
}
async postProcessUserInfo(tokenSet: TokenSet): Promise<OauthUserInfo> {
const url = new URL('https://graph.microsoft.com/v1.0/me');
url.searchParams.append('$select', 'id,displayName,mail,identities');
const rawUserInfo = await fetch(
'https://graph.microsoft.com/v1.0/me/',
url.toString(),
{
headers: {
Authorization: `Bearer ${tokenSet.access_token}`,
@ -35,6 +38,17 @@ export class MicrosoftProvider extends OAuthBaseProvider {
}
).then(res => res.json());
let email = rawUserInfo.mail;
if (!email) {
email = rawUserInfo.identities.find((identity: any) => {
if (identity.signInType === 'emailAddress') {
rawUserInfo.mail = identity.issuerAssignedId;
return true;
}
return false;
});
}
return validateUserInfo({
accountId: rawUserInfo.id,
displayName: rawUserInfo.displayName,