@Injectable({
provideIn: 'root'
})
export class AuthService {
private readonly _user$: BehaviourSubject<Account>;
constructor(private readonly _msalService: MsalService) {
this._user$ = new BehaviorSubject(_msalService.getAccount());
this._msalService.handleRedirectCallback((authError, response) => {
if (authError) {
this._msalService.loginRedirect({ scopes: ['openid'] });
return;
}
// window.location is always 'https://localhost:4200/#', looks like the other part of the #state=123&scope=456 is missing in the Angular
this._msalService.acquireTokenRedirect({ scopes: ['https://***.partner.onmschina.cn/api/write','https://***.partner.onmschina.cn/api/read'] }); });
this._user$.next(_msalService.getAccount());
}
public login() {
this._msalService.loginRedirect();
}
}
Token. Have a look at the aud - it's for the UI application. azp and scp are missing.
{
"iss": "https://***.b2clogin.cn/0b5***865/v2.0/",
"exp": 1595754060,
"nbf": 1595750460,
"aud": "706***cae", <-- Audience is for the UI application, not for the API applications
"oid": "cf2***062",
"sub": "cf2***062",
"given_name": "Vlad",
"family_name": "Kasianenko",
"name": "Vlad Kasianenko",
"emails": [
"Vladyslav_Kasianenko@companyemail.com"
],
"tfp": "B2C_1_signin",
"nonce": "8ef200db-c7ed-4506-a780-f65e6671e827",
"ver": "1.0",
"iat": 1595750460,
"auth_time": 1595750460,
}
Azure AD B2C setup:
When I call acquireTokenSilent({ scopes: ['https://***.partner.onmschina.cn/api/write','https://***.partner.onmschina.cn/api/read'] }), I actually got right token in the accessToken property. But how do I apply it to the Bearer?
After migrating from
msal@0.2.2
to themsal@1.3.3
I have different tokens. There were no changes at the Azure portal.After
_msalService.login()
I have this URL:However, with
acquireTokenRedirect
in the URL I have something like this:As you can see, this URL contains both scopes and valid token. But how can I grab it in the
handreRedirectCallback
?I also use
MsalGuard
, might it affect somehow?Am I missing something?
OLD configuration:
auth.service.ts
:NEW configuration:
MSAL_CONFIG
token:MSAL_CONFIG_ANGULAR
:auth.service.ts
:Token. Have a look at the
aud
- it's for the UI application.azp
andscp
are missing.Azure AD B2C setup:
When I call
acquireTokenSilent({ scopes: ['https://***.partner.onmschina.cn/api/write','https://***.partner.onmschina.cn/api/read'] })
, I actually got right token in theaccessToken
property. But how do I apply it to the Bearer?