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/".
step#3 in web.config file, copy clientid, tenantid , client secret azure ad portal.
step#4 run project in visual studio , log in azure ad account
the expected result should following:
you can click "clear cache database" button if have acquire token issues.
Comments
Post a Comment