Response to preflight request doesn't pass access control check:
I have an Identity Server v4 with an asp net core v2 >> localhost:5000 Also I have an Angular SPA with implicit flow >> localhost:4200
In Identity Server I added localhost:4200 as a CORS origin, which allow to any:
- AnyOrigin
- AnyHeader
- AnyMethod
but when in Angular I use this setting to connect to OIDC, I run into the CORS error.
{
authority: 'http://localhost:5000/',
client_id: 'spa',
redirect_uri: 'http://localhost:4200/auth-callback/',
post_logout_redirect_uri: 'http://localhost:4200/',
response_type: "token id_token",
scope: "openid profile api1",
filterProtocolClaims: true,
loadUserInfo: true,
automaticSilentRenew: true,
monitorSession: false
}
So I manually added meta data to UserManagerSetting:
metadata: {
issuer: "http://localhost:5000",
jwks_uri: "http://localhost:5000/.well-known/openid-configuration/jwks",
authorization_endpoint: "http://localhost:5000/connect/authorize",
token_endpoint: "http://localhost:5000/connect/token",
userinfo_endpoint: "http://localhost:5000/connect/userinfo",
end_session_endpoint: "http://localhost:5000/connect/endsession",
check_session_iframe: "http://localhost:5000/connect/checksession",
revocation_endpoint: "http://localhost:5000/connect/revocation",
introspection_endpoint: "http://localhost:5000/connect/introspect",
}
And then successfully redirect to OIDC and after login and accept connect page, It redirected to
'http://localhost:4200/auth-callback/'
But when I call :
this.manager.signinRedirectCallback().then(user => {
this.user = user;
});
This error this error occurs:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 405.
Error log: _ 2018-07-04 11:53:14.440 +04:30 [DBG] Using Identity.Application as default scheme for authentication 2018-07-04 11:53:14.531 +04:30 [DBG] Using Identity.External as default scheme for sign-in 2018-07-04 11:53:14.532 +04:30 [DBG] Using Identity.External as default scheme for sign-out 2018-07-04 11:53:14.533 +04:30 [DBG] Using Identity.Application as default scheme for challenge 2018-07-04 11:53:14.533 +04:30 [DBG] Using Identity.Application as default scheme for forbid 2018-07-04 11:53:15.470 +04:30 [DBG] Starting token cleanup 2018-07-04 11:54:16.153 +04:30 [INF] AuthenticationScheme: Identity.Application was successfully authenticated. 2018-07-04 11:54:16.571 +04:30 [INF] AuthenticationScheme: Identity.Application was successfully authenticated. 2018-07-04 12:53:16.438 +04:30 [INF] Clearing 0 tokens 2018-07-04 13:53:17.231 +04:30 [INF] Clearing 0 tokens 2018-07-04 14:53:17.551 +04:30 [INF] Clearing 0 tokens 2018-07-04 14:59:28.616 +04:30 [INF] AuthenticationScheme: Identity.Application was successfully authenticated. 2018-07-04 14:59:28.617 +04:30 [INF] AuthenticationScheme: Identity.Application was successfully authenticated. 2018-07-04 14:59:28.630 +04:30 [DBG] Request path /connect/authorize matched to endpoint type Authorize 2018-07-04 14:59:28.644 +04:30 [DBG] Endpoint enabled: Authorize, successfully created handler: IdentityServer4.Endpoints.AuthorizeEndpoint 2018-07-04 14:59:28.645 +04:30 [INF] Invoking IdentityServer endpoint: IdentityServer4.Endpoints.AuthorizeEndpoint for /connect/authorize 2018-07-04 14:59:28.761 +04:30 [DBG] Start authorize request 2018-07-04 14:59:28.803 +04:30 [DBG] User in authorize request: 1f72f614-f92a-4090-1641-08d5df9b3966 2018-07-04 14:59:29.053 +04:30 [DBG] Start authorize request protocol validation 2018-07-04 14:59:32.158 +04:30 [DBG] spa found in database: true 2018-07-04 14:59:32.512 +04:30 [DBG] Found ["openid","profile"] identity scopes in database 2018-07-04 14:59:33.423 +04:30 [DBG] Found ["api1"] API scopes in database 2018-07-04 14:59:33.655 +04:30 [DBG] Found ["openid","profile"] identity scopes in database 2018-07-04 14:59:34.142 +04:30 [DBG] Found ["api1"] API scopes in database 2018-07-04 14:59:34.162 +04:30 [DBG] Calling into custom validator: IdentityServer4.Validation.DefaultCustomAuthorizeRequestValidator 2018-07-04 14:59:34.430 +04:30 [INF] ValidatedAuthorizeRequest { "ClientId": "spa", "ClientName": "SPA Client", "RedirectUri": "http://localhost:4200/auth-callback/", "AllowedRedirectUris": [ "http://localhost:4200/auth-callback/", "http://localhost:4200/silent-refresh.html" ], "SubjectId": "1f72f614-f92a-4090-1641-08d5df9b3966", "ResponseType": "id_token token", "ResponseMode": "fragment", "GrantType": "implicit", "RequestedScopes": "openid profile api1", "State": "7cc540bc175849068b2cd9b6627ed0de", "Nonce": "a444d29c439f46a8ae0b1a4f5eee0756", "SessionId": "09e59f02567f443703e642168070c2e9", "Raw": { "client_id": "spa", "redirect_uri": "http://localhost:4200/auth-callback/", "response_type": "token id_token", "scope": "openid profile api1", "state": "7cc540bc175849068b2cd9b6627ed0de", "nonce": "a444d29c439f46a8ae0b1a4f5eee0756" } } 2018-07-04 14:59:34.687 +04:30 [DBG] aTf+svfybg7dMdd1JQSepJnOkycG3rhLs/KyLwR7FL8= found in database: true 2018-07-04 14:59:34.726 +04:30 [DBG] Consent found in consent store is same as current request, consent is not required 2018-07-04 14:59:34.740 +04:30 [DBG] Creating Implicit Flow response. 2018-07-04 14:59:34.766 +04:30 [DBG] Getting claims for access token for client: spa 2018-07-04 14:59:34.767 +04:30 [DBG] Getting claims for access token for subject: 1f72f614-f92a-4090-1641-08d5df9b3966 2018-07-04 14:59:38.277 +04:30 [DBG] Getting claims for identity token for subject: 1f72f614-f92a-4090-1641-08d5df9b3966 and client: spa 2018-07-04 14:59:38.279 +04:30 [DBG] In addition to an id_token, an access_token was requested. No claims other than sub are included in the id_token. To obtain more user claims, either use the user info endpoint or set AlwaysIncludeUserClaimsInIdToken on the client configuration. 2018-07-04 14:59:38.876 +04:30 [INF] { "Name": "Token Issued Success", "Category": "Token", "EventType": "Success", "Id": 2000, "ClientId": "spa", "ClientName": "SPA Client", "RedirectUri": "http://localhost:4200/auth-callback/", "Endpoint": "Authorize", "SubjectId": "1f72f614-f92a-4090-1641-08d5df9b3966", "Scopes": "openid profile api1", "GrantType": "implicit", "Tokens": [ { "TokenType": "id_token", "TokenValue": "****o5CQ" }, { "TokenType": "access_token", "TokenValue": "****Rikw" } ], "ActivityId": "0HLF1FS11K995:00000001", "TimeStamp": "2018-07-04T10:29:38Z", "ProcessId": 1936, "LocalIpAddress": "127.0.0.1:16930", "RemoteIpAddress": "::1" } 2018-07-04 14:59:38.884 +04:30 [INF] Authorize endpoint response { "SubjectId": "1f72f614-f92a-4090-1641-08d5df9b3966", "ClientId": "spa", "RedirectUri": "http://localhost:4200/auth-callback/", "State": "7cc540bc175849068b2cd9b6627ed0de", "Scope": "openid profile api1" } 2018-07-04 14:59:46.217 +04:30 [DBG] CORS request made for path: /connect/userinfo from origin: http://localhost:4200 2018-07-04 14:59:46.561 +04:30 [DBG] Origin http://localhost:4200 is allowed: false 2018-07-04 14:59:46.561 +04:30 [WRN] CorsPolicyService did not allow origin: http://localhost:4200 2018-07-04 14:59:46.563 +04:30 [DBG] Request path /connect/userinfo matched to endpoint type Userinfo 2018-07-04 14:59:46.566 +04:30 [DBG] Endpoint enabled: Userinfo, successfully created handler: IdentityServer4.Endpoints.UserInfoEndpoint 2018-07-04 14:59:46.566 +04:30 [INF] Invoking IdentityServer endpoint: IdentityServer4.Endpoints.UserInfoEndpoint for /connect/userinfo 2018-07-04 14:59:46.571 +04:30 [WRN] Invalid HTTP method for userinfo endpoint. _
After login the call back url is :
http://localhost:4200/auth-callback#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjI1ZTg1NDZmMTBiMWY0ZGUwM2RhMDVmNTBiMTc5ODhkIiwidHlwIjoiSldUIn0.eyJuYmYiOjE1MzA3MDI1MTQsImV4cCI6MTUzMDcwMjgxNCwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo1MDAwIiwiYXVkIjoic3BhIiwibm9uY2UiOiI2YzRlZWI5MWMzN2U0NDgzYTYwYWZlOGFmZmZkYjVlZSIsImlhdCI6MTUzMDcwMjUxNCwiYXRfaGFzaCI6ImdxSE5Vd0NmYjdEOG1MLW54U2NtNlEiLCJzaWQiOiIwOWU1OWYwMjU2N2Y0NDM3MDNlNjQyMTY4MDcwYzJlOSIsInN1YiI6IjFmNzJmNjE0LWY5MmEtNDA5MC0xNjQxLTA4ZDVkZjliMzk2NiIsImF1dGhfdGltZS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vg2XRGpCT46ZGTXvNhzN1fk9gi6ihyOJcNwR1V-zXqMuB-8JGlaCiSzlBv_PjanmCuezoqO-lo3LaB8ycxhoOehJO0sDFnXjg8h5muvxRJUB0JT7dPN3GlB3A&token_type=Bearer&expires_in=3600&scope=openid%20profile%20api1&state=14b5265f2eea4373aaa78a3be3140f30&session_state=XBqtkXMO81c5ulrSk4ybxA_0-bZSLLgzAdia9Jd9Ewc.9df7a239738d7e45f2c9daa566d3c9d4
But i don't have access to it as query string or something else
Did you solve this? @masoud-bahrami
@masoud-bahrami we've got the same problem, it would be great if you share how did you handle with it
@masoud-bahrami Got anything?