Azure b2c-Msal js-SPA-编辑配置文件

时间:2018-09-14 10:20:35

标签: azure-active-directory

有人用MSAL和spa尝试“个人资料编辑”吗?如果可以的话,请给我指出一些演示示例吗?预先感谢。

我能够集成“ SignIn”,“ SignUp”和“ PasswordReset”,但是在集成配置文件编辑时,它确实采用了“配置文件编辑”策略,但是问题是,应用程序要求再次登录以编辑用户资料。

下面是代码

 private clientApplication: Msal.UserAgentApplication;

  constructor(private router: Router, private token: tokenDataService) {

    this.clientApplication =
      new Msal.UserAgentApplication(
        environment.clientID,
        this.authority,
        this.authCallback.bind(this),
        {
          redirectUri: window.location.origin
        });
  }

  public login(): void {
    this.clientApplication.loginRedirect(environment.b2cScopes);
  }

  public editProfile() {
    let clientApp = window.msal as Msal.UserAgentApplication;
    clientApp.authority = this.profileEditAuthority;
    clientApp.loginRedirect(environment.b2cScopes);
  }

  public logout(): void {
    this.clientApplication.logout();
  }
  public firstLogin(): string {
    return this.clientApplication.getUser().idToken['newUser'];
  }
  public isOnline(): boolean {
    return this.clientApplication.getUser() != null;

  }

  public getUser(): User {

    return this.clientApplication.getUser();
  }

  public getAuthenticationToken(): Promise<string> {

    return this.clientApplication.acquireTokenSilent(environment.b2cScopes)
      .then(token => {
        this.token.set(token);
        console.log('hi')
        console.log(token);

        return token;
      }).catch(error => {
        return this.clientApplication.acquireTokenPopup(environment.b2cScopes)
          .then(token => {
            return Promise.resolve(token);
          }).catch(innererror => {
            console.error('Could not retrieve token from popup.', innererror);
            return Promise.resolve('');
          });
      });
  }

  private authCallback(errorDesc: any, token: any, error: any, tokenType: any) {
    this.router.navigate(['/pages/home']);

    if (error) {
      if (errorDesc.indexOf("AADB2C90118") > -1) {

        let clientApp = window.msal as Msal.UserAgentApplication;
        clientApp.authority = this.resetpasswordAuthority;

        clientApp.loginRedirect(environment.b2cScopes);
      }
      console.error(`${error} ${errorDesc}`);
    }
  }

0 个答案:

没有答案