将自定义参数传递给登录页面 Identity Server 4 中使用的 returnUrl

卡萨斯

我正在为使用混合流的客户端实现带有 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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何自定义所有WSO2 Identity Server登录相关页面

在Azure中使用Identity Server签名证书

如何通过桌面/移动应用程序使用Identity Server 4登录

Identity Server 4和Docker

Identity Server 4 + Identity Framework + React前端

角色-Identity Server 4

Identity Server 4 Cors问题

使用Ionic 2配置Identity Server 4

具有自定义生存期的Identity Server 4访问令牌

将自定义客户端服务添加到Identity Server 4之后的CORS错误

Identity Server 4中的自定义登录视图

如何使用Identity Server 4中的C#正确获取令牌以在Postman中使用?

将参数传递给Identity Server 4登录页面

Identity Server 4 / nativescript挂起

.Net Core自定义身份验证,使用带有Identity Server 4的API密钥

Identity Server 4无限循环

在Identity Server 4中使用参考令牌传递其他数据

登录Identity Server 4-.Net Core 2.2

如何将ReturnUrl传递到Blazor Server应用程序的“登录”页面?

Identity Server 4:如何仅为UserInfoEndpoint添加自定义声明,并将其排除在AccessToken中?

Identity Server 4登录现有数据库

使用Blazor Web程序集和Identity Server 4的登录错误

Identity Server4用户登录后选择帐户

如何将自定义登录失败通知传递给 MVC4 中的视图

在 Identity Server 4 中使用 fetch

如何在 Identity Server4 中使用 ASP.NET Idenity 使用 Azure AD 外部登录

安装 Identity Server 4 模板

Identity Server 4 with WebAuthN - 使用 GrantType (FIDO 2.0)

REST API 和 Identity Server 4 使用 Postman 进行测试