Typescript b2c msal用户没有现有会话和请求提示参数

Typescript b2c msal用户没有现有会话和请求提示参数,typescript,azure-ad-b2c,msal,Typescript,Azure Ad B2c,Msal,当我通过loginRedirect登录时,我可以看到MSAL令牌已在重定向上填充,但在尝试使用令牌时,我收到以下错误: 无法以静默方式从存储中检索令牌 AADB2C90077:用户没有现有会话,在通过连接到Azure B2C的Angular SPA应用程序成功登录后,请求提示参数的值为“None” 我在a中发现了类似的内容,然后在由于没有令牌而被迫执行tokenPopup()后出现错误时发表了评论: “此应用程序对此web资源没有足够的权限来执行此操作” 他们可能没有亲戚关系,但他们都阻止了我

当我通过
loginRedirect
登录时,我可以看到MSAL令牌已在重定向上填充,但在尝试使用令牌时,我收到以下错误:

无法以静默方式从存储中检索令牌

AADB2C90077:用户没有现有会话,在通过连接到Azure B2C的Angular SPA应用程序成功登录后,请求提示参数的值为“None”

我在a中发现了类似的内容,然后在由于没有令牌而被迫执行
tokenPopup()
后出现错误时发表了评论:

“此应用程序对此web资源没有足够的权限来执行此操作”

他们可能没有亲戚关系,但他们都阻止了我

在这段代码中,
loginredirect
起作用,我可以在本地存储中看到令牌,然后下次使用令牌时,我会收到控制台日志
authCallback err
然后记录“无法从存储中以静默方式检索令牌…”和首先提到的错误

@Injectable()
export class MsalService {
  private access_token: string;

  private tenantConfig = {
    tenant: environment.tenant,
    clientID: environment.clientID,
    signUpSignInPolicy: environment.signUpSignInPolicy,
    b2cScopes: environment.b2cScopes
  };

  private authority = "https://login.microsoftonline.com/tfp/" +
    this.tenantConfig.tenant +
    "/" +
    this.tenantConfig.signUpSignInPolicy;

  private clientApplication: Msal.UserAgentApplication;

  private authCallback(errorDesc: any, token: any, error: any, tokenType: any) {
    var _this = this;
    console.log("authCallback");
    // For loginRedirect, tokenType = "id_token". For acquireTokenRedirect, tokenType:"access_token".
    if (token) {
      console.log("authCallback- Id token", token);
      this.access_token = token;
    } else {
      console.log("authCallback-err : " + error + ":" + errorDesc);
      alert("error here");
    }
  }

  constructor() {
    this.clientApplication = new Msal.UserAgentApplication(
      this.tenantConfig.clientID,
      this.authority,
      this.authCallback,
      {
        cacheLocation: "localStorage",
        redirectUri: "https://localhost:4200/msallogin"
      }
    );
  }

  get authenticated() {
    const user = this.clientApplication.getUser();
    if (user) {
      return true;
    }
    return false;
  }

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

  public getAuthenticationToken(): Promise<string> {
    return this.clientApplication
      .acquireTokenSilent(this.tenantConfig.b2cScopes)
      .then(token => {
        console.log("Got silent access token: ", token);
        return token;
      })
      .catch(error => {
        console.log("Could not silently retrieve token from storage.", error);
        return this.clientApplication
          .acquireTokenPopup(this.tenantConfig.b2cScopes)
          .then(token => {
            console.log("Got popup access token: ", token);
            return token;
          })
          .catch(error => {
            console.log("Could not retrieve token from popup.", error);
            this.clientApplication.acquireTokenRedirect(
              this.tenantConfig.b2cScopes
            );
            return Promise.resolve("");
          });
      });
  }

  public login(): void {
    var _this = this;
    this.clientApplication.loginPopup(this.tenantConfig.b2cScopes).then(
      function(idToken: any) {
        _this.clientApplication
          .acquireTokenSilent(_this.tenantConfig.b2cScopes)
          .then(
            function(accessToken: any) {
              _this.access_token = accessToken;
              console.log("ACCESS TOKEN: \n " + _this.access_token);
            },
            function(error: any) {
              _this.clientApplication
                .acquireTokenPopup(_this.tenantConfig.b2cScopes)
                .then(
                  function(accessToken: any) {
                    _this.access_token = accessToken;
                  },
                  function(error: any) {
                    alert("Error acquiring the popup:\n" + error);
                  }
                );
            }
          );
      },
      function(error: any) {
        alert("Error during login:\n" + error);
      }
    );
  }

  logout(): void {
    this.clientApplication.logout();
  }

  isOnline(): boolean {
    return this.clientApplication.getUser() != null;
  }

  public getUser(): string {
    const user = this.clientApplication.getUser();
    if (!user) {
      return null;
    }

    return user.name;
  }
}
我的B2C作为邮递员应用程序连接到Azure功能,它肯定是B2C配置、我的代码或MSAL。我无法从B2C策略刀片修改这些设置,因此不确定他是如何解决的

B2c配置在中的注释中列出 我在这方面花了很多时间,这可能很容易,但由于不同应用程序的多个作用域以及作用域刀片服务器的不同问题和更改,这似乎比应该的更难

使用:

Angular: "5.2.0"
MSAL: "^0.1.5"
我也犯了同样的错误

我所做的是在登录策略的XML文件中添加了两行,这就解决了我的问题

<UserJourneyBehaviors>

<SessionExpiryType>Absolute</SessionExpiryType>

<SessionExpiryInSeconds>86400</SessionExpiryInSeconds>

</UserJourneyBehaviors>

绝对的
86400
我希望这会有帮助

<UserJourneyBehaviors>

<SessionExpiryType>Absolute</SessionExpiryType>

<SessionExpiryInSeconds>86400</SessionExpiryInSeconds>

</UserJourneyBehaviors>