2012-04-08 2 views
0

저는 개발중인 프로젝트에서 openID 인증을 소비자로 구현하려고 시도했지만, 원하는 경우에도 예제가 제대로 작동하지 않았습니다. .501 Google에서 OpenID를 사용하려고 할 때 HTTP 오류가 발생했습니다.

예제 소비자가 yahoo openid 인증을 위해 완벽하게 작동하더라도 google openID를 사용하려고 시도하면 try_auth.php 페이지에서 501 HTTP 오류로 실패합니다. ,

<?php 
error_reporting(E_ALL); 
ini_set('display_errors','On'); 
require_once "common.php"; 
session_start(); 

function getOpenIDURL() { 
    // Render a default page if we got a submission without an openid 
    // value. 
    if (empty($_GET['openid_identifier'])) { 
     $error = "Expected an OpenID URL."; 
     include 'index.php'; 
     exit(0); 
    } 

    return $_GET['openid_identifier']; 
} 

function run() { 
    $openid = getOpenIDURL(); 
    $consumer = getConsumer(); 

    // Begin the OpenID authentication process. 
    $auth_request = $consumer->begin($openid); 

    // No auth request means we can't begin OpenID. 
    if (!$auth_request) { 
     displayError("Authentication error; not a valid OpenID."); 
    } 

    $sreg_request = Auth_OpenID_SRegRequest::build(
            // Required 
            array('nickname'), 
            // Optional 
            array('fullname', 'email')); 

    if ($sreg_request) { 
     $auth_request->addExtension($sreg_request); 
    } 

    $policy_uris = null; 
    if (isset($_GET['policies'])) { 
     $policy_uris = $_GET['policies']; 
    } 

    $pape_request = new Auth_OpenID_PAPE_Request($policy_uris); 
    if ($pape_request) { 
     $auth_request->addExtension($pape_request); 
    } 

    // Redirect the user to the OpenID server for authentication. 
    // Store the token for this authentication so we can verify the 
    // response. 

    // For OpenID 1, send a redirect. For OpenID 2, use a Javascript 
    // form to send a POST request to the server. 
    if ($auth_request->shouldSendRedirect()) { 
     $redirect_url = $auth_request->redirectURL(getTrustRoot(), 
                getReturnTo()); 

     // If the redirect URL can't be built, display an error 
     // message. 
     if (Auth_OpenID::isFailure($redirect_url)) { 
      displayError("Could not redirect to server: " . $redirect_url->message); 
     } else { 
      // Send redirect. 
      header("Location: ".$redirect_url); 
     } 
    } else { 
     // Generate form markup and render it. 
     $form_id = 'openid_message'; 
     $form_html = $auth_request->htmlMarkup(getTrustRoot(), getReturnTo(), 
               false, array('id' => $form_id)); 

     // Display an error if the form markup couldn't be generated; 
     // otherwise, render the HTML. 
     if (Auth_OpenID::isFailure($form_html)) { 
      displayError("Could not redirect to server: " . $form_html->message); 
     } else { 
      print $form_html; 
     } 
    } 
} 

run(); 

?> 

는 또 다른 내가 나의 창에 dev에 박스 눈치 생각 (아파치 2.2.6 독립형 :

여기 try_auth.php에 대한 코드 (실제 오픈 아이디 제공 업체에 전화를 처리하는 페이지)의 XAMPP, PHP 5.3.8이 아님) 모든 것이 원활하게 실행됩니다. 야후와 Google은 아무런 문제없이 openID 인증을 수행합니다.

누구나 잘못된 생각 일 수 있습니까?

미리 감사드립니다.

+0

몇 가지 코드를 표시 할 수 있습니까? – Baba

+0

janrain openid와 함께 제공되는 소비자 코드 예입니다. 거기에서 한 줄의 코드를 변경하지 않았습니다. 나는 주 dev 컴퓨터에 접근하자마자 파일을 게시 할 것이다 ... – Yiangos

+0

'error_reporting (E_ALL);과'ini_set ('display_errors', 'On');'을 코드에 추가하고 정확한 PHP 오류 – Baba

답변

0

몇 가지 시행 착오 끝에 Google 오픈 ID URL이 쿼리 문자열 (양식 메소드 "get") 또는 양식 데이터 (양식 메소드 "get")로 전달됨으로 인해 501 오류가 발생했습니다. 게시하다"). 특히, I 사용 된 URL을

https://www.google.com/accounts/o8/id

, 마지막 부분 ("ID")는 501 에러를 유발된다. 내가

https://www.google.com/accounts/o8/id/

를 사용하는 경우 오류가 트리거되지 않습니다. 두 URL은 동등한 URL이므로 두 번째 URL을 사용합니다. 나는 아직도 이것이 왜 일어나고 있는지 궁금하다.

관련 문제