0

我正在使用 Microsoft.Owin.Security.Facebook 3.0.1 NuGet 包将 Facebook 身份验证添加到我的 Web API 2.2 应用程序中。我有这样的代码,当用户尝试登录时,微软的中间件将他们重定向到 Facebook 的 OAuth 对话框,其 URL 如下:

https://www.facebook.com/dialog/oauth?response_type=code&client_id=<omitted>&redirect_uri=<omitted>&scope=&state=<omitted>

我希望生成的 HTTP 302 呈现 Facebook 的特定于弹出式版本的身份验证对话框。Facebook 的文档说我可以将display查询字符串字段的值设置为popup. display不幸的是,微软的 Facebook 中间件似乎没有设置。事实上,在反编译内部Microsoft.Owin.Security.Facebook.FacebookAuthenticationHandler类时,我发现了这段代码:

string redirectUri = this.get_Options().AuthorizationEndpoint + "?response_type=code&client_id=" + Uri.EscapeDataString(this.get_Options().AppId) + "&redirect_uri=" + Uri.EscapeDataString(stringToEscape1) + "&scope=" + Uri.EscapeDataString(stringToEscape2) + "&state=" + Uri.EscapeDataString(stringToEscape3);

似乎无法自定义身份验证处理程序生成的 URL。

我的问题是,有没有人遇到过这个问题并解决了它?我可以在管道的其他地方做些什么来以某种方式添加display到 URL 中吗?我需要使用 Facebook 的 OAuth 对话框的弹出版本。

我尝试了一个委托处理程序,我看到它拦截了管道中生成的 HTTP 401,但它没有拦截 HTTP 302。

顺便说一句,将其作为功能请求的合适位置在哪里?

4

1 回答 1

0

尽管我认为这个解决方案比我想要的更多,但它确实有效。我创建了一个 IIS URL 重写规则,该规则附加&display=popup到其 Location 标头与 Facebook 的 OAuth 对话 URL 匹配的任何 HTTP 302 响应上:

<rewrite>
  <outboundRules>
    <rule name="Append display query string field onto Facebook OAuth dialog redirects" preCondition="HTTP 302">
      <match serverVariable="RESPONSE_Location" pattern="^https://www\.facebook\.com/dialog/oauth\?.*" />
      <action type="Rewrite" value="{R:0}&amp;display=popup" />
    </rule>
    <preConditions>
      <preCondition name="HTTP 302">
        <add input="{RESPONSE_STATUS}" pattern="302" />
      </preCondition>
    </preConditions>
  </outboundRules>
</rewrite>

我不会将此标记为已接受的答案,希望有一个不依赖于 URL 重写的更好的解决方案。

于 2015-02-20T19:18:52.840 回答