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標題未被應用?
我沒有足夠的時間來形成完整的回覆,但是我可以確認我正在使用IdS3而沒有「Access-Control-Allow-Origin」問題。查看示例存儲庫中的JSImplicitClient示例以獲取指導。我一直在遇到'訪問控制 - 允許 - 方法'的問題,但這不是你所問的。 –