fix(ui): msal authentictor to share UserProfile object on login success (#17302)

This commit is contained in:
Chirag Madlani 2024-08-06 15:53:14 +05:30 committed by GitHub
parent a98a39fc11
commit 92b2c6c353
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,6 +18,7 @@ import {
} from '@azure/msal-browser';
import { useAccount, useMsal } from '@azure/msal-react';
import { AxiosError } from 'axios';
import { get } from 'lodash';
import React, {
forwardRef,
Fragment,
@ -34,6 +35,7 @@ import { Transi18next } from '../../../utils/CommonUtils';
import {
AuthenticatorRef,
OidcUser,
UserProfile,
} from '../AuthProviders/AuthProvider.interface';
interface Props {
@ -80,15 +82,21 @@ const MsalAuthenticator = forwardRef<AuthenticatorRef, Props>(
const parseResponse = (response: AuthenticationResult): OidcUser => {
// Call your API with the access token and return the data you need to save in state
const { idToken, scopes, account } = response;
const user = {
id_token: idToken,
scope: scopes.join(),
profile: {
email: account?.username || '',
email: get(account, 'idTokenClaims.email', ''),
name: account?.name || '',
picture: '',
sub: '',
},
preferred_username: get(
account,
'idTokenClaims.preferred_username',
''
),
sub: get(account, 'idTokenClaims.sub', ''),
} as UserProfile,
};
setOidcToken(idToken);