我正在为使用混合流的客户端使用IdentityServer4实现身份验证服务器。我设法实现了自己的用户存储以及我自己的客户端,资助和资源存储库。
当用户想要登录时,客户端会将其重定向到我的身份验证服务器,如果没有插入,则会显示登录页面。此时我需要一些额外的信息而不是用户名和密码才能登录我的用户。这是来自另一个系统的projectId,我实际上是对用户进行身份验证。客户应提供此projectId。
流程看起来像这样:
我在这里阅读Sending Custom Parameters to login screen
我应该从AccountController中的returnUrl中检索参数。我现在触发登录流程的方式是使用我的客户端代码中的控制器方法中的[Authorize]属性:
[Route("login")]
[Authorize]
public async Task<IActionResult> Login()
我的问题是:
1.如何将connect / authorize请求中的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
};
非常感谢你的帮助。
答案 0 :(得分:0)
您应该能够简单地将其他查询字符串参数添加到授权端点请求,然后将它们从MVC控制器中的returnUrl解析为登录流。任何不属于协议的东西都会被IDS4忽略我很确定。