azure - Office 365 - multitenant application constantly gives unauthorized -
for reason following code gives unauthorized exception, can tell me i'm doing wrong?
in screenshot below can find contents of "thetoken", has been received through office365 , saved in database ( 1 minute before excecution)
async function calendardemo() system.threading.tasks.task(of actionresult) dim tokendata = usertokenservice.gettoken(httpcontext.user.identity.name) dim thetoken = tokendata.readitems(0) dim mycalendars list(of viewmodels.office365.mycalendar) = new list(of viewmodels.office365.mycalendar) try dim accesstoken func(of string) = function() string return thetoken.accesstoken end function dim discclient new discoveryclient(new uri("https://api.office.com/discovery/v1.0/me/"), accesstoken) dim dcr = await discclient.discovercapabilityasync("calendar") 'this code breaks, code worked in past. till split authorization , fetching of calendar viewbag.resourceid = dcr.serviceresourceid dim exclient new outlookservicesclient(dcr.serviceendpointuri, function() return helpers.office365helpers.returnstringasasync(thetoken.accesstoken) end function) dim calendarresults = await exclient.[me].events.executeasync() dim calenderresults = await exclient.me.calendar.events.executeasync() dim calendars = calendarresults.currentpage each calendar in calendars dim newcalendar = new viewmodels.office365.mycalendar(calendar) mycalendars.add(newcalendar) next calendarresults = await calendarresults.getnextpageasync() loop while calendarresults isnot nothing catch exception adalexception ' handle token acquisition failure if exception.errorcode = adalerror.failedtoacquiretokensilently 'authcontext.tokencache.clear() 'redirect naar login of refresh token viewbag.errormessage = "authorizationrequired" end if catch exception discoveryfailedexception end try return view(mycalendars) end function the exception : "exception of type ' microsoft.office365.discovery.discoveryfailedexception' thrown." - , errorcode 'unauthorized'
according answer below, changed following code:
dim exclient new outlookservicesclient(new uri("https://outlook.office365.com/api/v1.0/"), function() return helpers.office365helpers.returnstringasasync(thetoken.accesstoken) end function) dim calendarresults = await exclient.[me].events.take(10).executeasync() where helper :
public module office365helpers public async function returnstringasasync(toreturnstring string) system.threading.tasks.task(of string) return await system.threading.tasks.task.delay(1).continuewith(function(dl) toreturnstring) end function end module but doesn't return value when it's loading.. it's api call in continuous loop.
identitical question shorter:
i have microsoft.identitymodel.clients.activedirectory.tokencache, how can query microsoft calendar api using dll's , vb.net data.
in odataexception, in response, can view header values.
there error there explains fault, said in lines of : "inconsistent resource". true. found out didn't use https://outlook.office365.com/api/v1.0/ when requesting token. used when requesting data.
so received invalid tokens tried do.
Comments
Post a Comment