2012-09-11 4 views
0

37 신호 'Basecamp API에 대한 OAuth2 인증을 처리하기 위해 CodeIgniter 컨트롤러를 작성하려고합니다.OAuth2를 사용한 Basecamp API 인증 : 내부 체크섬 실패 오류

HTTP 헤더에 인증 토큰을 제공하여 https://launchpad.37signals.com/authorization.json에 (cURL을 통해) 연결할 때 '내부 체크섬 실패'오류가 계속 발생하는 문제가 있습니다.

여기 내 컨트롤러 클래스에서 인덱스와 _authcode 기능입니다 : VARCHAR (255)와 데이터베이스의 인증 토큰을 저장할 때

<?php 

// constants: 
// BC_REQUEST_URL = 'https://launchpad.37signals.com/authorization/new' 
// BC_TOKEN_URL = 'https://launchpad.37signals.com/authorization/token' 

// ... 

public function index() { 
    // if get data is set. 
    if ($this->input->get()) { 

     // if auth code is provided via GET, switch to _authcode method. 
     if ($code = $this->input->get('code')) { 
      return $this->_authcode($code); 
     } 

     // On error, kill yourself. 
     if ($error = $this->input->get('error')) { 
      die($error); 
     } 

    } 

    // redirect to 37 signals to get an authcode 
    header("Location: ".BC_REQUEST_URL."?type=web_server&client_id=".BC_CLIENT_ID."&redirect_uri=".BC_REDIRECT_URL.""); 
} 

// handles the Authentication code that is returned by 37 Signals. 
private function _authcode($code) { 
    // set vars to POST 
    $vars = array(
     'type' => 'web_server', 
     'client_id' => BC_CLIENT_ID, 
     'redirect_uri' => BC_REDIRECT_URL, 
     'client_secret' => BC_CLIENT_SECRET, 
     'code' => $code 
    ); 

    // make a request for the access_token 
    $url = BC_TOKEN_URL; 
    $c = curl_init($url); 
    curl_setopt($c, CURLOPT_POST, true); 
    curl_setopt($c, CURLOPT_POSTFIELDS, http_build_query($vars)); 
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true); 
    $response = json_decode(curl_exec($c)); 
    curl_close($c); 
    unset($c,$url); 

    // get the access vars from this request 
    $expiry_seconds = $response->expires_in; // default: 1209600 (14 days) 
    $refresh_token = $response->refresh_token; 
    $access_token = $response->access_token; 
    unset($response); 

    // make a separate request to get user info for current user. 
    $url = "https://launchpad.37signals.com/authorization.json"; 
    $c = curl_init($url); 

    curl_setopt($c, CURLOPT_HTTPHEADER, array(
     "Authorization: Bearer <$access_token>", 
     "Content-Type: application/json; charset=utf-8", 
     "User-Agent: MyApp (http://myapp.example.com)" 
    )); 
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true); 
    $response = json_decode(curl_exec($c)); // reply from 37 signal auth 
    curl_close($c); 
    unset($c,$url); 

    echo "response obj = " . print_r($response,1); 
    /* prints: response obj = stdClass Object ([error] => OAuth token could not be verified. The internal checksum failed, so the token data was somehow mangled or tampered with.) */ 

    // get the user data from this request 
    // $expires_at = $response->expires_at; // the timestamp for when this request expires 
    // $identity = $response->identity; // the current user 
    // $accounts = $response->accounts; // list of accounts we can access 
    // unset($response); 

    // store the response data to the database for easy recall. 
    // $this->db->query("REPLACE INTO `sometable` SET `key1`='value', `key2`='value'); 

} 
// ... 
?> 

답변

1

나는이 오류에 달렸다. Basecamp의 인증 토큰에는 255 자 이상의 토큰을 가져 오는 체크섬 데이터가 있습니다.

예제에서 데이터베이스에서 가져 오지 않은 것 같습니다. 따라서 영향을받지 않을 수도 있지만, Basecamp의 토큰이 잘리는 지 확인하는 것은 내가 처음 보게되는 것입니다.

선택적으로 Bearer 헤더를 설정할 때 $ access_token에서 <>자를 제거하십시오.

+0

'<' and '>'을 제거하면 트릭을 만들었습니다. 감사! – Jazzerus