我正在使用 DotNetOpenAuth 通过 OAuth2 连接到 Facebook 和 Google。OAuth 规范要求在 request_uri 中不提供其他参数,Google 实际上通过在您使用它们定义 Google 应用程序时强制指定确切的回调 uri 来强制执行此操作。
我想要完成的是能够在用户通过 Facebook 或 Google 的身份验证后将其返回到特定的 URL。流程是这样的,用户点击一个受保护的链接,他们通过 returnUrl 参数被转发到我的登录页面,然后我根据他们选择的 OAuth2 授权服务器启动授权过程。
由于 request_uri 中不能有任何参数(尽管 Facebook 让你侥幸逃脱),我无法将 returnUrl 参数发送到授权服务器并将其取回,这样当用户返回我的网站时,我将他们转发到他们试图访问的受保护页面。我能做的最好的就是将它们转发到主页或会员欢迎页面。
解决此问题的方法是使用授权服务器将发送回 request_uri 的“状态”参数,但我找不到使用 DotNetOpenAuth 指定它的方法。
默认情况下,代码使用 SessionID 作为状态参数来验证从授权服务器返回的请求。在 WebServerClient 类上指定 IClientAuthorizationTracker 可让我在响应从授权服务器返回时插入我的逻辑,但在准备授权请求时不会调用它,因此我无法插入我的附加状态。
这是来自 WebServerClient.cs 的 PrepareRequestUserAuthorization 的代码:
// Mitigate XSRF attacks by including a state value that would be unpredictable between users, but
// verifiable for the same user/session.
// If the host is implementing the authorization tracker though, they're handling this protection themselves.
if (this.AuthorizationTracker == null) {
var context = this.Channel.GetHttpContext();
if (context.Session != null) {
request.ClientState = context.Session.SessionID;
} else {
Logger.OAuth.WarnFormat("No request context discovered, so no client state parameter could be set to mitigate XSRF attacks.");
}
}
这里没有其他块,这是我期望能够播放并插入我自己的数据的。
关于我所缺少的任何提示?