我在我的OAuth控制器中爲我的Authorize方法有一個自定義授權過濾器。當授權過濾器記錄用戶登錄時,它會將當前OAuth請求填入會話中,並將其發送到會話中。傳遞HttpRequestWrapper時來自DotNetOpenAuth的ReadAuthorizationRequest的錯誤消息
登錄後,在我的/ OAuth/Authorize端點中,檢查是否請求在會話中,而不是立即失敗,因爲沒有附加到當前請求的授權請求。然後,我用該請求對象調用授權服務器。
在我的授權採取行動的代碼如下所示:但是
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
[ExternalAppAuthorizeAttribute]
public ActionResult Authorize() {
Object requestObject = this.HttpContext.Session["AuthRequest"];
HttpRequestBase request = null;
if ((requestObject != null) && (requestObject.GetType() == typeof(HttpRequestWrapper)))
{
request = (HttpRequestWrapper)requestObject;
this.HttpContext.Session.Remove("AuthRequest");
}
EndUserAuthorizationRequest pendingRequest = null;
if (request != null)
{
pendingRequest = this.authorizationServer.ReadAuthorizationRequest(request);
} else
{
pendingRequest = this.authorizationServer.ReadAuthorizationRequest();
}
if (pendingRequest == null) {
throw new HttpException((int)HttpStatusCode.BadRequest, "Missing authorization request.");
}
ReadAuthorizationRequest失敗,當請求在會話中發現和恢復。該錯誤消息不是非常有幫助:「值沒有在預期範圍之內。」
這裏是堆棧跟蹤:
[ArgumentException: Value does not fall within the expected range.]
System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) +0
System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) +10
System.Web.Util.Misc.ThrowIfFailedHr(Int32 hresult) +9
System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name) +36
System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name) +49
System.Web.HttpRequest.AddServerVariableToCollection(String name) +22
System.Web.HttpRequest.FillInServerVariablesCollection() +85
System.Web.HttpServerVarsCollection.Populate() +36
System.Web.HttpServerVarsCollection.Get(String name) +42
System.Collections.Specialized.NameValueCollection.get_Item(String name) +10
DotNetOpenAuth.Messaging.MessagingUtilities.GetPublicFacingUrl(HttpRequestBase request, NameValueCollection serverVariables) +61
DotNetOpenAuth.Messaging.MessagingUtilities.GetPublicFacingUrl(HttpRequestBase request) +43
DotNetOpenAuth.Messaging.Channel.ReadFromRequestCore(HttpRequestBase request) +69
我已經檢查了我的請求,在飛行中,一切都在used by oauth它看起來完全罰款:標題,URI等。我不知道是什麼原因造成的。
有誰知道爲什麼這可能是這種情況?或者,如果您在用戶進行身份驗證時有其他建議來存儲oauth請求,我向他們開放。