如何填充OwinContext.Request.Path和PathBase?

 百变精灵_tb 发布于 2022-12-23 16:48

我正在根据Katana项目中的其他示例为OpenID Connect授权代码流编写自己的OWIN中间件.

作为其中的一部分,我必须构造一些URI,例如重定向URI和返回URL.

Katana中的其他示例通过连接当前请求中的部分来完成此操作,例如在CookieAuthenticationHandler中

loginUri =
    Request.Scheme +
    Uri.SchemeDelimiter +
    Request.Host +
    Request.PathBase +
    Options.LoginPath +
    new QueryString(Options.ReturnUrlParameter, currentUri);

我的问题是什么规则管理两个路径属性中的最终结果:

OwinContext.Request.Path
OwinContext.Request.PathBase

我已经尝试检查这些属性,因为请求通过下面管道中的不同处理程序,请求:

"https://localhost/Client/login" // Where Client is a virtual directory in IIS

结果:

在/ login的映射处理程序中,PathBase ="/ Client/Login".

但是当请求到达同一请求的路上时,我的QuillCodeFlowHandler中的ApplyResponseChallengeAsync方法得到了,PathBase ="/ Client"和Path ="/ Login".

因此,如果不知道如何填充这些值的"规则",然后更改,则很难使用它们构造URI.如果有人能解释,将不胜感激.

我的配置的摘录是:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
    LoginPath = new PathString("/Login")
});

app.UseQuillCodeFlowAuthentication(new QuillCodeFlowOptions());

app.Map("/login", map =>
{
   map.Run(async ctx =>
   {
     if (ctx.Authentication.User == null ||
     !ctx.Authentication.User.Identity.IsAuthenticated)
     {                        
       var authenticationProperties = new AuthenticationProperties();
       [...]
       ctx.Authentication.Challenge(authenticationProperties,
                                    QuillCodeFlowDefaults.AuthenticationType);  

该OWIN规范给出了一些解释和Microsoft.Owin.Host.HttpListener.GetPathAndQuery方法似乎是在路径变量的初始设置.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有