离子 3 - 阿达尔女士 :: 如何缓存数据并重新发送



下面是我使用 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)
});
});;
});

有人可以帮助我吗??

您可以使用 ionic 存储插件 https://ionicframework.com/docs/native/native-storage 或 sqlite 插件 https://ionicframework.com/docs/building/storage 来存储数据。

最新更新