Disqus OAuth无效授权

时间:2014-01-10 22:16:40

标签: php oauth oauth-2.0 disqus

当我尝试使用带有Disqus的OAuth时,我一直收到此错误:

{"error_description":"Invalid parameter: redirect_uri","error":"invalid_grant"}

我的代码如下所示 - 示例1:

$oauth2token_url = 'https://disqus.com/api/oauth/2.0/access_token/';
        $redirect_uri = 'http://www.example.com/';
        $clienttoken_post = array(
            "grant_type" => 'authorization_code',
            "client_id" => PVConfiguration::getConfiguration('disqus') -> public_key,
            "client_secret" => PVConfiguration::getConfiguration('disqus') -> private_key,
            "redirect_uri" => $redirect_uri,
            "code" => $this -> registry -> get['code']
        );

        $curl = curl_init($oauth2token_url);

        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
        curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

        $json_response = curl_exec($curl);
        curl_close($curl);

        print_r($json_response);

或者这 - 示例2:

$url = 'https://disqus.com/api/oauth/2.0/access_token/';
        $fields = array(
            'grant_type'    =>  'authorization_code',
            'client_id'     =>  PVConfiguration::getConfiguration('disqus') -> public_key,
            'client_secret' =>  PVConfiguration::getConfiguration('disqus') -> private_key,
            'redirect_uri'  =>  'http://www.example.com/',
            //'scope' => 'read,write,email',
            'code'          =>  $this -> registry -> get['code'],
        );

        $fields_string  = '';
        //url-ify the data for the POST
        foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
        rtrim($fields_string, '&');

        //open connection
        $ch = curl_init();

        //set the url, number of POST vars, POST data
        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_POST, count($fields));
        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

        //execute post
        $result = curl_exec($ch);

        //close connection
        curl_close($ch);

        print_r($result);

        exit();

任何人都可以提供任何指示吗?

1 个答案:

答案 0 :(得分:0)

想出来。文档在这里:

http://tools.ietf.org/html/rfc6749#section-4.1.3

但问题源于错误的api错误消息。在请求授权时,重定向uri获取代码必须与uri完全相同。