使用swasbuckle的Swagger UI使我在从Azure登录重定向时出现CORS起源问题

时间:2018-10-03 20:24:27

标签: asp.net-core asp.net-core-2.0 asp.net-core-webapi swashbuckle

发出请求且令牌已过期后,我面临swashbuckle和登录重定向的新问题。 description 我真的不知道这是一个常见问题还是无法解决,这就是我提出这个问题的原因。 我对api enponit的请求可以很好地重定向,但是当我单击swagger UI上的Execute按钮时,对https://localhost:port/api/v1/Contacts的请求,响应为302,然后尝试将我重定向到此问题的登录提供者,我无法重定向再次登录。image 2

我在这里缺少什么??

这是我的身份验证配置:

 //Add  Auth options
        services.AddAuthentication(options =>
        {
            options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            options.DefaultAuthenticateScheme = OpenIdConnectDefaults.AuthenticationScheme;
        })
        .AddOpenIdConnect(options =>
        {
            options.ClientId = ClientId;
            options.Authority = $"{Instance}/{TenantId}";
            options.SignedOutRedirectUri = SignedOutRedirectUri;
            // Add needed scopes
            options.Scope.Add("openid");
            options.Scope.Add("profile");
            options.Scope.Add("roles");

            options.AuthenticationMethod = OpenIdConnectRedirectBehavior.RedirectGet;
            options.SaveTokens = true;

            options.Events = new OpenIdConnectEvents
            {
                OnRemoteFailure = context =>
                {
                    context.HandleResponse();
                    return Task.CompletedTask;
                }
            };

        })
        .AddCookie()
       .AddAzureAdBearer(options => configuration.Bind("bearer", options));

0 个答案:

没有答案