基於Katana項目中的其他示例,我正在爲OpenID Connect授權代碼流編寫我自己的OWIN中間件。OwinContext.Request.Path和PathBase如何填充?
作爲這個的一部分,我必須構建一對URI,例如重定向URI和返回URL。
在卡塔納其他的例子從當前請求拼接部分做到這一點,例如在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
其結果是:
- 在用於/登錄,PathBase = 「/客戶端/登錄」 所映射的處理程序。
- 但當請求到達我的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 specification給出了一些解釋和Microsoft.Owin.Host.HttpListener.GetPathAndQuery方法似乎是在路徑變量的初始設置。