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