【问题标题】:Preserve query string保留查询字符串
【发布时间】:2018-07-25 02:06:34
【问题描述】:

我将 Identity server 4 与 sitefinity 客户端一起使用。我正在使用查询字符串中传递的自定义值构造一个安全 api 的 url。 (例如:http://localhost:60876/Sitefinity?code=CfDJ8GIUky)。我试图在重定向到 ID4 之前捕获代码的值,但是该值消失了。以下是我的通知设置:

Notifications = new OpenIdConnectAuthenticationNotifications()
{
    RedirectToIdentityProvider = n =>
    {
        // trying to intercept the request to catch the query string value!
        return Task.FromResult(0);
    }
}

任何帮助将不胜感激。 谢谢

【问题讨论】:

    标签: c# query-string identityserver4


    【解决方案1】:

    经过两天的研究,这是我想出来的

    1- 我创建了一个可公开访问的端点来捕获查询字符串并保留它

    public ActionResult Index(string code)
    {
        return new ChallengeResult("OpenIdConnect", "http://localhost:60876", code);
    }
    

    2- ChallengeResult 接受代码并将其添加到 AuthenticationProperties

    var properties = new AuthenticationProperties() { RedirectUri = RedirectUri };
    if (Code != null)
    {
        properties.Dictionary["AccessCode"] = Code;
    }
    context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
    

    3- 在中间件 RedirectToIdentityProvider 中

    Notifications = new OpenIdConnectAuthenticationNotifications()
    {
        SecurityTokenValidated = context => SecurityTokenValidatedInternal(context),
        RedirectToIdentityProvider = context =>
        {
            var code = context.OwinContext.Authentication.AuthenticationResponseChallenge.Properties.Dictionary["AccessCode"];
            context.ProtocolMessage.SetParameter("Code", code);
            return Task.FromResult(0);
        }
    }
    

    但是字典条目不存在。我错过了什么吗?

    【讨论】:

      猜你喜欢
      • 2018-05-11
      • 2014-11-12
      • 1970-01-01
      • 2012-10-04
      • 2015-03-30
      • 1970-01-01
      • 2017-06-09
      • 2014-06-09
      • 1970-01-01
      相关资源
      最近更新 更多