adal - Azure B2C - Failed to acquire token silently -


i'm building application asp.net mvc , webapi using template : azure ad b2c webapp / wepapi. i've configured azure b2c ad through web.config files , when click "sign in" see identity providers. login works far (i see username on top right corner) , i'm able execute "to-do list"-action.

but stop debugger , restart application pressing f5, error when click on "to-do list"-action again.

failed acquire token silently. call method acquiretoken text --> code

this happens, cause user still authenticated, naivesessioncache empty after applications restart. possible solution be, store token in onauthorizationcodereceived handler, looks little bit weird me

    private async task onauthorizationcodereceived(authorizationcodereceivednotification notification)     {         string userobjectid = notification.authenticationticket.identity.findfirst("http://schemas.microsoft.com/identity/claims/objectidentifier").value;         string authority = string.format(cultureinfo.invariantculture, aadinstance, tenant, string.empty, string.empty);         clientcredential credential = new clientcredential(clientid, clientsecret);          string mostrecentpolicy = notification.authenticationticket.identity.findfirst(startup.acrclaimtype).value;         authenticationcontext authcontext = new authenticationcontext(authority);          authenticationresult result = await authcontext.acquiretokenbyauthorizationcodeasync(notification.code, new uri(redirecturi), credential, new string[] { clientid }, mostrecentpolicy);          // store token in claimsidentity         notification.authenticationticket.identity.addclaim(new system.security.claims.claim("token", result.token));     } 

your cache empty because not being persisted anywhere. check out http://www.cloudidentity.com/blog/2014/07/09/the-new-token-cache-in-adal-v2/. search efadaltokencache , find implementation persist cache storage.

azure b2c supported via new library called msal available @ https://www.nuget.org/packages/microsoft.identity.client. library still under preview.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -