Azure AD身份验证在不活动后失败

时间:2017-02-02 10:08:09

标签: c# azure asp.net-core asp.net-core-mvc

我们正在开发.net核心Azure Web应用程序,对于身份验证,我们使用cookie身份验证和开放ID连接身份验证。

当我们进入应用程序的起始页面时,一切都按照预期进行。但是让页面处于非活动状态大约10分钟,然后点击页面中的任何链接,我们得到以下异常:

XMLHttpRequest cannot load https://login.microsoftonline.com/f505412d-3150-4f15-a704-b6ce122de04d/oaut…mdOd12SMYufhag1Ysv-9E2WHXJHApMyfCDDaVtKQ4pcaiB7PyUpieC2a51_AvlB4f5KL7oN21C. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:54538' is therefore not allowed access.

但是,当一切都按照它的假设重新刷新时。有谁见过这个问题并找到了解决方案吗?

我们的启动文件在方法配置中包含以下代码:

app.UseSession();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
  AutomaticAuthenticate = true,
  AutomaticChallenge = true,
  LoginPath = new PathString("/Authentication/Login")
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
  ClientId = Configuration["Authentication:AzureAd:ClientId"],
  Authority = Configuration["Authentication:AzureAd:AADInstance"] + Configuration["Authentication:AzureAd:TenantId"],
  PostLogoutRedirectUri = Configuration["Authentication:AzureAd:PostLogoutRedirectUri"]
});

在方法ConfigureServices中:

services.AddDistributedMemoryCache();
services.AddSession(options =>
{
  options.CookieName = "cBook.Session";
  options.IdleTimeout = TimeSpan.FromHours(1);
});
services.AddMvc(options =>
{
  options.Filters.Add(new ExceptionFilter());
  options.Filters.Add(new ActiveDirectoryAuthorizationFilter());
  options.Filters.Add(new AuthorizeFilter(
    new AuthorizationPolicyBuilder()
      .RequireAuthenticatedUser()
      .Build()
  ));
});
services.AddAuthentication(sharedOptions => sharedOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton(_ => Configuration);

我很感激能得到的所有帮助。

谢谢, 一月

0 个答案:

没有答案