下面是我与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)
});
});;
});
有人可以帮我吗?
您可以使用离子存储插件https://ionicframework.com/docs/native/native-storage或sqlite插件https://ionicframework.com/docs/building/storage来存储数据。