0

Scenario :

I am logged-in through an AD B2C account in my Angular application. I have integrated msal-browser (^2.15.0) and msal-angular (^2.0.1), for authentication and to access session data.

I use Graph API (from my .NET server) to update my AD B2C User record from my Angular application.

Requirement :

Whenever I update the User record through Graph APIs (indirectly through my server) from my Angular application, I want my browser session to reflect those changes as well.

// user-data.service.ts

public updateUserRecord(userUpdateObj: CustomUserModel) {
 this.http.put("https://my-server-calling-graph-api.com/user-data", userUpdateObj ,this.HTTP_OPTIONS)
  .pipe(
    map((updatedResult: CustomUserModel) => {
     console.log('Updated User Record -> ', updatedResult);

     // SESSION DATA
     this.usersList = this.msalService.instance.getAllAccounts();
     this.msalService.instance.setActiveAccount(this.usersList[0]);
     const userCustomAttributes = this.usersList[0].idTokenClaims;

     console.log('Existing User Record -> ', userCustomAttributes);
    }),
    retry(2)
  );
} // FN

Question : Is there a way to silently get the session data updated in the background through any msal service calls or should I redirect to login to receive the session data freshly?

Prakash M.
  • 479
  • 8
  • 26

1 Answers1

1

The only way to achieve this is to call acquireTokenRedirect() or ssoSilent() MSAL method. These use cookie based logins which will then reprocess the user journey and fetch the latest data. ssoSilent() occurs in a hidden iframe. You may find, due to replication delays, that this still doesn't work reliably.

To avoid this issue, the end user can edit their user profile using an Edit Profile flow. This would be the recommended path.

Jas Suri - MSFT
  • 10,605
  • 2
  • 10
  • 20