如何在 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屋!