2010-03-26 31 views
0

我試圖用一個單一的HttpHandler來驗證用戶的開放ID和接收claimresponse幫助。初始身份驗證有效,但聲明響應沒有。我收到的錯誤是「這個網頁有一個重定向循環。」我究竟做錯了什麼?需要使用.NET的OpenID的HttpHandler

public class OpenIdLogin : IHttpHandler 
{ 
    private HttpContext _context = null; 

    public void ProcessRequest(HttpContext context) 
    { 
     _context = context; 
     var openid = new OpenIdRelyingParty(); 
     var response = openid.GetResponse(); 
     if (response == null) 
     { 
      // Stage 2: user submitting Identifier 
      openid.CreateRequest(context.Request.Form["openid_identifier"]).RedirectToProvider(); 
     } 
     else 
     { 
      // Stage 3: OpenID Provider sending assertion response 
      switch (response.Status) 
      { 
       case AuthenticationStatus.Authenticated: 
        //FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier, false); 
        string identifier = response.ClaimedIdentifier; 

        //****** TODO only proceed if we don't have the user's extended info in the database ************** 

        ClaimsResponse claim = response.GetExtension<ClaimsResponse>(); 
        if (claim == null) 
        { 
         //IAuthenticationRequest req = openid.CreateRequest(identifier); 
         IAuthenticationRequest req = openid.CreateRequest(Identifier.Parse(identifier)); 

         var fields = new ClaimsRequest(); 
         fields.Email = DemandLevel.Request; 
         req.AddExtension(fields); 
         req.RedirectingResponse.Send(); //Is this correct? 
        } 
        else 
        { 
         context.Response.ContentType = "text/plain"; 
         context.Response.Write(claim.Email); //claim.FullName; 
        } 
        break; 
       case AuthenticationStatus.Canceled: 
     //TODO 
        break; 
       case AuthenticationStatus.Failed: 
     //TODO 
        break; 
      } 
     } 
    } 

回答

0

通常情況下,一旦您收到一個已接受的請求,您希望存儲聲明的標識符並將其用於會話的其餘部分。該消息可能意味着提供者拒絕您的請求,因爲它認爲您有重定向循環。不要驗證每個請求上的ID,您應該接受該用戶的身份驗證,直到會話結束。

2

重定向循環是因爲如果你得到一個肯定的說法不回電子郵件發送用戶右後衛自討苦吃......一遍又一遍......麻煩的是,一些有機磷農藥永遠不會給你一個電子郵件地址。而這些相同的操作系統可能會立即重定向到另一個缺乏電子郵件地址的肯定斷言。

若權利要求不回來了積極的斷言,您需要向用戶展示自己的頁面,要求他親自這些說法。

+0

謝謝!雖然,我還沒有測試過,但你的回答很有意義!那麼我需要做的是有一種機制,只要索賠一次,無論索賠請求是否成功。 – 2010-03-28 04:48:54