I'm adding Microsoft Authentication to Firebase. I'm able to login successfully but I need the user's email and display name. How can I fetch this? So far this is what I have.
export function* signInWithMicrosoft() {
yield microsoftProvider.setCustomParameters({
prompt: 'consent',
tenant: 'consumers',
});
const res = yield signInWithPopup(auth, microsoftProvider);
try {
const credential = yield OAuthProvider.credentialFromResult(res);
const { accessToken, idToken } = credential;
yield console.log(credential);
} catch (err) {
return err;
}
}
You can make use of Microsoft Graph API to get signed-in user's email and display name by running below query:
To run the above query, you need to add
User.Readpermission in your Azure AD application like below:As you already have access token, just modify your code to run
GETrequest like below:You can also decode the access token by pasting it in jwt.ms and check
scpclaim for permissions it has:When I ran the same
GETrequest in Postman by including Bearer token, I got response successfully with signed-in user's email and display name like below:Response: