我正在为使用混合流的客户端实现带有 IdentityServer4 的身份验证服务器。我设法实现了我自己的用户存储以及我自己的客户、赠款和资源存储库。
当用户想要登录时,客户端会将其重定向到我的身份验证服务器,如果未登录,则会显示登录页面。在这一点上,我需要一些除了用户名和密码之外的额外信息才能登录我的用户。这是来自另一个系统的 projectId,我实际上正在对用户进行身份验证。客户端应提供此 projectId。
流程如下所示:
我在这里阅读了将自定义参数发送到登录屏幕
我应该从我在 AccountController 中获得的 returnUrl 检索参数。我现在触发登录流程的方式是在我的客户端代码的控制器方法中使用 [Authorize] 属性:
[Route("login")]
[Authorize]
public async Task<IActionResult> Login()
我的问题是:
1.如何将连接/授权请求中的projectId发送到身份服务器?
2.我应该为此手动创建请求吗?
2.a 如果是这样,那么我如何处理控制器中的重定向 uri 操作?因为现在我正在使用 /signin-oidc 标准路线。
我的客户定义如下所示:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies";
options.Authority = "http://localhost:5001";
options.RequireHttpsMetadata = false;
options.ClientId = "BGServer";
options.ClientSecret = "ThisIsTheBGServerSecret";
options.ResponseType = "code id_token"; //"code";
//set SaveTokens to save tokens to the AuthenticationProperties
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("BG_API");
options.Scope.Add("offline_access");
});
}
我在身份验证服务器中的客户端定义如下所示:
// OpenID Connect hybrid flow and client credentials client (BGServerClient)
new Client
{
ClientId = "BGServer",
ClientName = "BabyGiness Server",
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
RequireConsent = false,
ClientSecrets =
{
new Secret("ThisIsTheBGServerSecret".Sha256())
},
RedirectUris = {"http://localhost:5005/signin-oidc"},
PostLogoutRedirectUris = { "http://localhost:5005/signout-callback-oidc" },
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"BG_API"
},
AllowOfflineAccess = true //used to be able to retrieve refresh tokens
};
非常感谢您的帮助。
您应该能够简单地向授权端点请求添加额外的查询字符串参数,然后从您的 MVC 控制器中的 returnUrl 解析它们以用于登录流。IDS4 将忽略不属于协议的任何内容,我很确定。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句