-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenId Cross-origin requests #808
Comments
Yes. Note: I'm considering adding such support directly in OpenIddict, but if I did, it would be only for the OpenIddict-managed endpoints and you'd have to create your own policy for your own APIs anyway. |
Perhaps this is a different issue altogether, but I ran into a CORS issue with the UserInfo endpoint called from an external SPA. |
I could not find any reference to Cors in O2, so I briefly thought about a possible solution, at least for the UserInfo endpoint but hopefully taking into account the bigger picture:
In fact, only step 1 and 5 are really needed to get going, the rest is just some automation. I'd be happy to put together a PoC for this. |
If cors is not mandatory for openid, then we can still have a cors module but no dependency. In the openid module then we create a Startup class with a |
The |
Cool |
You can start a PR, I assume you need it so you are best at least solve your issues. Then we'll get some comments from Sergio and Kevin. On my side I will probably worry about how/when configuration is done, and flowed to the middleware which is itself quite configurable. Not sure how granular we need to be, and how to expose it (configuration files, site settings). Using controller attributes will then forcibly imply a direct dependency on the feature itself (if a controller uses this attribute, it's feature will enable CORS by default using the manifest). |
It is not clear to me what the purpose of Orchard.Cors module will be, Will it expose some abstractions in order to allow to other modules register their Cors policies? Why each module can not just use standard services.UseCors(..) middleware? |
If each module uses their own middleware, there will be multiple of them running at the same time. Also, the configuration might have to be defined by the user, and not hard coded in a module, that will depend. Policies can be defined in services, so each feature could define some, but they are registered in the middleware declaration, so it's a dead end. |
I will try to make a PR next week, thanks |
I'm no longer so sure it would be useful to have OpenID application-specific CORS rules. I suggest a simpler plan:
|
I guess the problem might be in Origins, they should not be hardcoded. Probably we may create an Orchard Features with ICorsHandlers which may read CORS policies from "Configuration file" AND/OR "Database". |
OR we may just leave DefaultCorsPolicyProvider as is, and allow Modules register their own CORS policies by standard way .AddCors + create a feature which will supply CORS policies via DB/Config file This is the way how I did in my app
In code above, in case if "MyFeature.Cors" feature is enabled, I'm reading CORS policies from DB |
The problem with this approach is that you can't add path-based policies in |
Can you please give an example of path-based CORS? this is not clear to me |
@rserj here's a concrete example: public class OpenIdCorsProvider : ICorsPolicyProvider
{
private readonly IOptionsMonitor<OpenIddictOptions> _options;
public OpenIdCorsProvider(IOptionsMonitor<OpenIddictOptions> options)
{
_options = options;
}
public Task<CorsPolicy> GetPolicyAsync(HttpContext context, string policyName)
{
var options = _options.Get(OpenIdConnectServerDefaults.AuthenticationScheme);
// Note: the authorization and logout endpoints are interactive endpoints that are
// susceptible of using forms of persistent authentication like Basic, Cookies or
// Windows Integrated Authentication (e.g NTLM, Kerberos/Negociate). As such, they
// MUST NOT be included in a CORS policy. To prevent these endpoints from being
// accidentally included in a CORS policy, an empty policy is returned here.
if (context.Request.Path.IsEquivalentTo(options.AuthorizationEndpointPath) ||
context.Request.Path.IsEquivalentTo(options.LogoutEndpointPath))
{
return Task.FromResult(new CorsPolicy());
}
// Note: the discovery/introspection/revocation/token/userinfo endpoints are
// non-interactive endpoints that don't use persistent authentication and
// are not allowed to return any authentication or session cookie. As such,
// they can be safely included in a lenient allow-all-origin CORS policy.
if (context.Request.Path.IsEquivalentTo(options.ConfigurationEndpointPath) ||
context.Request.Path.IsEquivalentTo(options.CryptographyEndpointPath) ||
context.Request.Path.IsEquivalentTo(options.IntrospectionEndpointPath) ||
context.Request.Path.IsEquivalentTo(options.RevocationEndpointPath) ||
context.Request.Path.IsEquivalentTo(options.TokenEndpointPath) ||
context.Request.Path.IsEquivalentTo(options.UserinfoEndpointPath))
{
return Task.FromResult(new CorsPolicy
{
Methods = { HttpMethods.Get, HttpMethods.Post },
Origins = { CorsConstants.AnyOrigin }
});
}
// If the request path doesn't correspond to an OpenID endpoint, return null
// to indicate that another policy might be selected by another provider.
return Task.FromResult<CorsPolicy>(null);
}
} |
Note: for internal applications (i.e applications that can't be accessed from Internet), we may want to make this allow-all policy opt-out, in case administrators would be concerned about the OpenID endpoints being directly reachable from a remote site via AJAX. |
@PinpointTownes thanks for an example. |
That's why I suggested introducing an
If we decide to go with "CORS policies as options" (implemented as an Honestly, I have no strong opinion about that. Both options have their pros/cons. |
Is there any temporary method to deal with this? |
Is there any update on this issue? |
We now have a CORS module that takes care of applying global CORS policies and the interactive/"non-API" OpenID endpoints - like the authorization endpoints - have been decorated with Closing. |
I just wondering how Orchard Open Id handling Cross-origin requests. I tested "Resource Owner Password Credentials" flow. I have to add CORS policy in order to allow make requests from my host, but it is kinda hardcode.
I think Admin should be able to specify "Application Host" while creating "OpenID Connect Application" in Admin tool.
Then each request with clientId/bearToken should be validated for registered "Application Host", if validation get passed server should issue "Access-Control-Allow-Origin" header in response with registered Host, (like Access-Control-Allow-Origin: foo.com)
OpenIddict does not support it out of the box
openiddict/openiddict-core#28
Do we need to implement it by ourself?
The text was updated successfully, but these errors were encountered: