billions-king-90430
01/30/2023, 1:47 PMmagnificent-energy-493
billions-king-90430
01/30/2023, 2:52 PMconst provider =
await this.context.aadTokenProviderFactory.getTokenProvider();
this._token = (await provider.getToken(
_spPageContextInfo.spfx3rdPartyServicePrincipalId
)) as string;
On the backend, the token can be verified with Azure AD javascript MSAL library like
const cca = new msal.ConfidentialClientApplication(msalConfig);
export class MyAuthenticationProvider implements AuthenticationProvider {
/**
* This method will get called before every request to the msgraph server
* This should return a Promise that resolves to an accessToken (in case of success) or rejects with error (in case of failure)
* Basically this method will contain the implementation for getting and refreshing accessTokens
*/
async getAccessToken() {
const authResponse = await cca.acquireTokenByClientCredential(tokenRequest);
if (authResponse.accessToken && authResponse.accessToken.length !== 0) {
return authResponse.accessToken;
} else {
throw new UnauthorizedException('cannot obtain access token');
}
}
}
So the backend is confident that it gets a valid token from an Azure AD authenticated user.
This user has a unique Azure AD ID, that we could store in the identity admin_metadata I suppose.billions-king-90430
01/30/2023, 3:03 PMbillions-king-90430
01/30/2023, 3:35 PMbillions-king-90430
01/30/2023, 3:51 PMmagnificent-energy-493
billions-king-90430
01/31/2023, 11:15 AM