c# - "Failed to acquire token silently. Call method AcquireToken" -


try {     clientcredential clientcredential = new clientcredential("***********","**************");     useridentifier useridentifier = new useridentifier(userobjectid, useridentifiertype.uniqueid);      discoveryclient discclient = new discoveryclient(settingshelper.discoveryserviceendpointuri,         async () =>         {             var authresult = await authcontext.acquiretokensilentasync(settingshelper.discoveryserviceresourceid,                                                                        clientcredential, useridentifier);              return authresult.accesstoken;         });      var dcr = await discclient.discovercapabilityasync(capabilityname);      return new outlookservicesclient(dcr.serviceendpointuri,         async () =>         {             var authresult = await authcontext.acquiretokensilentasync(dcr.serviceresourceid, clientcredential, useridentifier);             return authresult.accesstoken;         }); } catch (adalexception exception) {     //handle token acquisition failure     if (exception.errorcode == adalerror.failedtoacquiretokensilently)     {         authcontext.tokencache.clear();         throw exception;     }     return null; } 

giving error "failed acquire token silently. call method acquiretoken"

please ensure app registered under office 365 tenant ad, else fail discover , consume office 365 services.

step#1 download sample project aspnetmvc-with-o365.zip.

step#2 register app under office 365 tenant ad, declare office 365 exchange online > read user mail permission , set reply url "http://localhost:2659/". enter image description here

step#3 in web.config file, copy clientid, tenantid , client secret azure ad portal.

enter image description here

step#4 run project in visual studio , log in azure ad account

the expected result should following:

enter image description here

you can click "clear cache database" button if have acquire token issues.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -