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示例以獲取指導。我一直在遇到'訪問控制 - 允許 - 方法'的問題,但這不是你所問的。 –

相關問題