如何在ASP.NET Core的OpenIdConnectOptions上设置redirect_uri参数 [英] How to set redirect_uri parameter on OpenIdConnectOptions for ASP.NET Core
问题描述
我正在尝试使用OpenId将ASP.NET应用程序连接到Salesforce,目前,这是到目前为止的连接代码.我想我除了redirect_uri参数外,其他所有东西都必须完全匹配另一端的值.
I'm trying to connect an ASP.NET application to Salesforce using OpenId, Currently this is my connecting code so far. I think I got everything except the redirect_uri parameter, which has to match the value on the other end exactly.
app.UseCookieAuthentication(x =>
{
x.AutomaticAuthenticate = true;
x.CookieName = "MyApp";
x.CookieSecure = CookieSecureOption.Always;
x.AuthenticationScheme = "Cookies";
});
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap = new Dictionary<string, string>();
app.UseOpenIdConnectAuthentication(x =>
{
x.AutomaticAuthenticate = true;
x.Authority = "https://login.salesforce.com";
x.ClientId = "CLIENT_ID_HERE";
x.ResponseType = "code";
x.AuthenticationScheme = "oidc";
x.CallbackPath = new PathString("/services/oauth2/success");
//x.RedirectUri = "https://login.salesforce.com/services/oauth2/success";
x.Scope.Add("openid");
x.Scope.Add("profile");
x.Scope.Add("email");
});
但是RedirectUri不是要传递的有效参数.正确的设置方法是什么?
But RedirectUri isn't a valid parameter to pass. What is the right way to set it?
推荐答案
redirect_uri
是使用从当前请求中提取的方案,主机,端口和路径以及您指定的CallbackPath
自动为您计算的.
redirect_uri
is automatically computed for you using the scheme, host, port and path extracted from the current request and the CallbackPath
you specify.
x.RedirectUri = "https://login.salesforce.com/services/oauth2/success"
看起来非常可疑(除非您为Salesforce工作):别忘了它是身份验证流程完成后用户代理将重定向到的回调URL,而不是身份提供商的授权端点.
x.RedirectUri = "https://login.salesforce.com/services/oauth2/success"
looks highly suspicious (unless you work for Salesforce): don't forget it's the callback URL the user agent will be redirected to when the authentication flow completes, not the authorization endpoint of your identity provider.
因此,在您的情况下,用户将被重定向到http(s)://yourdomain.com/services/oauth2/success
.是您在Salesforce选项中注册的地址吗?
So in your case, the user will be redirected to http(s)://yourdomain.com/services/oauth2/success
. Is it the address you registered in your Salesforce options?
这篇关于如何在ASP.NET Core的OpenIdConnectOptions上设置redirect_uri参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!