Ionic 3-Adal女士::如何缓存数据并重新发送

问题描述 投票:0回答:1

下面是我与Ionic 3配合使用的MS ADAL的工作代码。

const SsoConfig = {
      "authority": "https://login.windows.net/common",
      "resourceUrl": "https://graph.windows.net",
      "clientId": [clientId]
      "redirectUrl": "https://login.microsoftonline.com/common/oauth2/nativeclient"
    };

let authContext: AuthenticationContext = this.msAdal.createAuthenticationContext(SsoConfig.authority);
authContext.acquireTokenAsync(SsoConfig.resourceUrl, SsoConfig.clientId, SsoConfig.redirectUrl, "", "")
      .then((authResponse: AuthenticationResult) => {
        console.log(authResponse);
      })
      .catch((e: any) => {
        console.log('Authentication failed')
      });

现在,使用以上代码,我每次必须登录。它不存储数据。因此,我尝试使用以下代码,但无法正常工作。

authContext.tokenCache.readItems().then(function (catchItems: any) {
      if (catchItems.length > 0) {
        authority = catchItems[0].authority;
        console.log(catchItems);
      }

      authContext.acquireTokenSilentAsync(SsoConfig.resourceUrl, SsoConfig.clientId, "")
        .then((silentAuthResponse: AuthenticationResult) => {
          console.log(silentAuthResponse);
        })
        .catch((e: any) => {          
          authContext.acquireTokenAsync(SsoConfig.resourceUrl, SsoConfig.clientId, SsoConfig.redirectUrl, "", "")
            .then((authResponse: AuthenticationResult) => {              
              console.log(authResponse);
            })
            .catch((e: any) => {
              this.Message = "Authentication failed";
              console.log(e)
            });
        });;
    });

有人可以帮我吗?

ionic3 angular5 adal
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.