1

使用Identity Server 3我试图按照documentation来配置CORS。当我执行GET请求时,我可以看到在Fiddler中捕获的响应是正确的,并且缺少Access-Control-Allow-Origin标头。跨域请求被阻止:CORS头'Access-Control-Allow-Origin'丢失

这里是用来设置代码的IdentityServerOptions

public void Configuration(IAppBuilder app) 
{ 
    var factory = InMemoryFactory.Create(
     clients: Clients.Get(), 
     scopes: Scopes.Get()); 

    var viewOptions = new DefaultViewServiceOptions(); 
    viewOptions.Stylesheets.Add("/Content/site.css"); 
    viewOptions.Scripts.Add("/Content/logon.js"); 
    viewOptions.CacheViews = false; 
    factory.ConfigureDefaultViewService(viewOptions); 

    // This is where the CORS policy service is configured. 
    var corsPolicyService = new DefaultCorsPolicyService(); 
    corsPolicyService.AllowAll = true; 
    factory.CorsPolicyService = new Registration<ICorsPolicyService>(corsPolicyService); 

    var userService = new LocalRegistrationUserService(); 
    factory.UserService = new Registration<IUserService>(resolver => userService); 

    var options = new IdentityServerOptions 
    { 
     SiteName = "IdentityServer", 
     SigningCertificate = this.certificateProvider.Certificate, 
     Factory = factory, 
     RequireSsl = true, 

     // This is deprecated, but should still work according to the documentation. 
     // However using or not using it makes no change. 
     // CorsPolicy = CorsPolicy.AllowAll, 

     ProtocolLogoutUrls = logoutUrls, 
     AuthenticationOptions = new AuthenticationOptions() 
     { 
      EnableSignOutPrompt = false, 
      EnablePostSignOutAutoRedirect = true, 
      PostSignOutAutoRedirectDelay = 5,      
     }, 
    }; 

    app.Map("/core", idsrvApp => 
    { 
     idsrvApp.UseIdentityServer(options); 
    }); 
} 

如果我那么做,从不同的站点简单GET的要求,这是响应我得到:

HTTP/1.1 302 Found 
Content-Length: 0 
Location: https://federation.example.com/core/login?signin=2ce0b4f...71313af 
Server: Microsoft-IIS/8.5 
Set-Cookie: SignInMessage.2ce0b4f...A1D5NkPJQ; path=/core; secure; HttpOnly 
X-Powered-By: ASP.NET 
Date: Mon, 13 Jul 2015 12:00:00 GMT 

为什么Access-Control-Allow-Origin标题未被应用?

回答

0

看起来,CORS策略服务正在Identity Server 3中正确设置,但所请求的路径是明确不可用通过不同的服务器。

请求的路径,在记录表中的错误鉴定为:

CORS请求路径发:/连接/从产地认证:空,但被拒绝,因为无效CORS路径

我相信这是为了防止恶意系统在未经用户同意的情况下对用户进行签名的额外安全措施。

因此,可以在工厂的Client.RedirectUris(对于隐式流)中定义唯一可以调用此受保护路径的系统。

+0

我没有足够的时间来形成完整的回复,但是我可以确认我正在使用IdS3而没有“Access-Control-Allow-Origin”问题。查看示例存储库中的JSImplicitClient示例以获取指导。我一直在遇到'访问控制 - 允许 - 方法'的问题,但这不是你所问的。 –

相关问题