asp.net core - Azure AD Authentication error: failed_to_acquire_token_silently -


at random intervals, asp.net mvc core application throws error while attempting authenticate users via azure ad openidconnect:

failed_to_acquire_token_silently 

and workaround has been truncate adal's database table usertokencache.

not sure doing wrong in owin pipeline configuration.

once user authenticated, want acquire token graph api in order retrieve additional claims azure ad.

exception gets thrown catch block

 accesstoken = authenticationcontext.acquiretoken("https://graph.windows.net",              clientcredential).accesstoken; 

here complete method:

        /// <summary>     /// method has been adapted generated code new asp.net mvc 5 project template     /// when using organisational accounts authentication.     /// method acquires token azure ad in order call graph api.     /// token acquired using logged in user's refresh token.      /// </summary>     /// <param name="context"></param>     /// <returns></returns>     private async task<string> gettokenforapplicationasync()     {         clientcredential clientcredential =             new clientcredential(                 configuration["authentication:azuread:clientid"],                 configuration["authentication:azuread:clientsecret"]);          authenticationcontext authenticationcontext =             new authenticationcontext(                 configuration["authentication:azuread:aadinstance"] +                 configuration["authentication:azuread:tenantid"],                 new adaltokencacheservice(signedinuserid, configuration));          string accesstoken = null;         try         {             authenticationresult authenticationresult = await authenticationcontext.acquiretokensilentasync(                      configuration["authentication:azuread:graphresource"],                     clientcredential,                     new useridentifier(userobjectid, useridentifiertype.uniqueid));              accesstoken = authenticationresult.accesstoken;         }         catch (adalexception e)         {             accesstoken = authenticationcontext.acquiretoken("https://graph.windows.net",                  clientcredential).accesstoken;          }          return accesstoken;     } 

i have looked @ this post not same issue dealing with.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -