无法以静默方式获取令牌。在示例应用上调用方法AcquireToken

时间:2016-10-30 22:49:47

标签: c# .net azure-active-directory adal

我在这里使用这个样本:

  public async Task<ActionResult> Index()
        {
            var eventsResults = new List<MyEvent>();
            var accessToken = await GetGraphAccessTokenAsync();

            try
            {
                var graphService = GetGraphServiceClient(accessToken);
                var request = graphService.Me.Events.Request(new Option[] { new QueryOption("top", "20"), new QueryOption("skip", "0") });
                var userEventsCollectionPage = await request.GetAsync();
                foreach (var evnt in userEventsCollectionPage)
                {
                    eventsResults.Add(new MyEvent
                    {
                        Subject = !string.IsNullOrEmpty(evnt.Subject) ? evnt.Subject : string.Empty,
                        Start = !string.IsNullOrEmpty(evnt.Start.DateTime) ? DateTime.Parse(evnt.Start.DateTime) : new DateTime(),
                        End = !string.IsNullOrEmpty(evnt.End.DateTime) ? DateTime.Parse(evnt.End.DateTime) : new DateTime()

                    });
                }
            }
            catch (Exception el)
            {
                el.ToString();
            }

            ViewBag.Events = eventsResults.OrderBy(c => c.Start);
            return View();
        }

练习#3 https://github.com/OfficeDev/TrainingContent/blob/master/O3651/O3651-5%20Getting%20started%20with%20Office%20365%20APIs/Lab.md

然而我得到了错误

Failed to acquire token silently. Call method AcquireToken

Descripción: Excepción no controlada al ejecutar la solicitud Web actual. Revise el seguimiento de la pila para obtener más información acerca del error y dónde se originó en el código. 

Detalles de la excepción: Microsoft.IdentityModel.Clients.ActiveDirectory.AdalSilentTokenAcquisitionException: Failed to acquire token silently. Call method AcquireToken

Error de código fuente: 


Línea 60:             // create auth context
Línea 61:             AuthenticationContext authContext = new AuthenticationContext(SettingsHelper.AzureAdAuthority, new ADALTokenCache(signInUserId));
Línea 62:             var result = await authContext.AcquireTokenSilentAsync(SettingsHelper.AzureAdGraphResourceURL, clientCredential, userIdentifier);
Línea 63: 
Línea 64:             return result.AccessToken

谢谢

0 个答案:

没有答案