mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
updated MS get email method
This commit is contained in:
parent
a0781f1e44
commit
630a67bd56
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user