首页 > 解决方案 > 将变量传递给 OpenId Connect RedirectToIdentityProvider/动态设置 acr 值

问题描述

在我的 Owin 启动中,我使用 OpenId 配置登录

在 Notifications -> RedirectToIdentityProvider 中,我需要根据用户输入设置提示和 acr 值。

由于配置是在启动期间完成的,并且那时我不知道用户输入,所以我不能在设置 openId 时只传递值。

触发登录时,我得到了我需要的用户输入,然后触发了 Notifications -> RedirectToIdentityProvider。这就是我需要设置提示和 acr 值的地方。但是我如何在这里传递它们?

 public static void ConfigureCriiptoAuth(this IAppBuilder app, string loginMethod, string postLoginRedirectUri, string pLoginId = null)
    {
        string tenant = ConfigurationManager.AppSettings["CriiptoDomain"];
        string clientId = ConfigurationManager.AppSettings["CriiptoId"];
        string clientsecret = ConfigurationManager.AppSettings["CriiptoSecret"];

        app.UseCookieAuthentication(new CookieAuthenticationOptions { });

        var idOptions = new OpenIdConnectAuthenticationOptions
        {
            ClientId = clientId,
            ClientSecret = clientsecret,
            Authority = tenant,
            ResponseType = "code",
            ResponseMode = OpenIdConnectResponseMode.Query,
            Caption = "Criipto",
            Scope = OpenIdConnectScope.OpenIdProfile,
            RedirectUri = "https://localhost:44357/",
            SignInAsAuthenticationType = "Cookies",
            RedeemCode = true,
            SaveTokens = true,
            Notifications = new OpenIdConnectAuthenticationNotifications()
            {
                RedirectToIdentityProvider = ctx => {
                    //HERE I NEED TO SET AcrValues and LoginHint, 
                    //based on user inputs and not on values passed in at startup
                    ctx.ProtocolMessage.AcrValues = loginMethod;                      
                    if(pLoginId != null)
                    {               
                        ctx.ProtocolMessage.LoginHint = pLoginId;
                    }
                    ctx.ProtocolMessage.RedirectUri = postLoginRedirectUri;
                    return Task.FromResult(0);
                }
            }
        };

        app.UseOpenIdConnectAuthentication(idOptions);
    }

标签: c#openid-connectopenid

解决方案


推荐阅读