I’m using Ionic 3 MS ADAL and its returning data. But the thing is, when we apply Adal service in a web application, it stores data by default. But for a ionic 3 app, how could I store data or validating the stored data?? Every time its asking for the user name and password.
Below is my working Code for MS ADAL with Ionic 3.
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')
});
Now, with the above code I have to login every time. Its not storing the data. So, I tried with the below code, but its not working.
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)
});
});;
});
Could someone help me on this??