如何在 ASP.NET 核心的 OpenIdConnectOptions 上设置 redirect_uri 参数
How to set redirect_uri parameter on OpenIdConnectOptions for ASP.NET Core
我正在尝试使用 OpenId 将 ASP.NET 应用程序连接到 Salesforce,目前这是我目前的连接代码。我想我得到了除 redirect_uri 参数之外的所有内容,该参数必须与另一端的值完全匹配。
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 不是要传递的有效参数。正确的设置方法是什么?
redirect_uri
是使用从当前请求中提取的方案、主机、端口和路径以及您指定的 CallbackPath
自动计算的。
x.RedirectUri = "https://login.salesforce.com/services/oauth2/success"
看起来非常可疑(除非你为 Salesforce 工作):不要忘记它是回调 URL 用户代理将在身份验证流程完成时被重定向到,而不是授权端点您的身份提供者。
因此在您的情况下,用户将被重定向到 http(s)://yourdomain.com/services/oauth2/success
。这是您在 Salesforce 选项中注册的地址吗?
您需要为 OnRedirectToIdentityProvider
设置事件侦听
你的情况:
x.Events.OnRedirectToIdentityProvider = async n =>
{
n.ProtocolMessage.RedirectUri = <Redirect URI string>;
await Task.FromResult(0);
}
我正在尝试使用 OpenId 将 ASP.NET 应用程序连接到 Salesforce,目前这是我目前的连接代码。我想我得到了除 redirect_uri 参数之外的所有内容,该参数必须与另一端的值完全匹配。
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 不是要传递的有效参数。正确的设置方法是什么?
redirect_uri
是使用从当前请求中提取的方案、主机、端口和路径以及您指定的 CallbackPath
自动计算的。
x.RedirectUri = "https://login.salesforce.com/services/oauth2/success"
看起来非常可疑(除非你为 Salesforce 工作):不要忘记它是回调 URL 用户代理将在身份验证流程完成时被重定向到,而不是授权端点您的身份提供者。
因此在您的情况下,用户将被重定向到 http(s)://yourdomain.com/services/oauth2/success
。这是您在 Salesforce 选项中注册的地址吗?
您需要为 OnRedirectToIdentityProvider
你的情况:
x.Events.OnRedirectToIdentityProvider = async n =>
{
n.ProtocolMessage.RedirectUri = <Redirect URI string>;
await Task.FromResult(0);
}