PHP7 oAuth请求失败

时间:2016-02-20 11:54:55

标签: php oauth

我有一个使用BitBucket API和oAuth的工作登录过程,我正在尝试迁移到php7。

在PHP 5.6上运行正常,然后我使用此页面的信息https://www.digitalocean.com/community/tutorials/how-to-upgrade-to-php-7-on-centos-7

将服务器升级到PHP7

我还升级了oAuth pecl包版本,以使用为PHP7制作的新2.0.0。 oAuth请求停止工作并返回“无效的请求令牌。”

我尝试卸载oAuth软件包2.0.0并重新安装1.2.3,但安装失败并带有

In file included from /var/tmp/oauth/oauth.c:14:0:
/var/tmp/oauth/php_oauth.h:35:40: fatal error: ext/standard/php_smart_str.h: No such file or directory
#include "ext/standard/php_smart_str.h"

这似乎是尝试在PHP7上为PHP 5.x安装包的常见错误,因为他们将php_smart_str重命名为php_smart_string(根据phpredis包github上的错误报告https://github.com/phpredis/phpredis/issues/682#issuecomment-163743879

我想oAuth软件包可能会因为1.2.3而失败,但我在文档中看不到有关它的信息。

这是代码

<?php
include 'includes/includes.php';
$req_url = 'https://bitbucket.org/api/1.0/oauth/request_token';
$authurl = 'https://bitbucket.org/api/1.0/oauth/authenticate';
$acc_url = 'https://bitbucket.org/api/1.0/oauth/access_token';
$api1_url = 'https://bitbucket.org/api/1.0/';
$api2_url = 'https://bitbucket.org/api/2.0/';

$callback_url="http://".$_SERVER['SERVER_NAME']."/bitbucket_login.php";

$conskey = 'mykey';
$conssec = 'mysecret';

session_start();
if(empty($_SESSION['user']))
{
    // In state=1 the next request should include an oauth_token.
    // If it doesn't go back to 0
    if(!isset($_GET['oauth_token']) && $_SESSION['state']==1) $_SESSION['state'] = 0;
    try {
        $oauth = new OAuth($conskey,$conssec,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
        $oauth->enableDebug();
        if(!isset($_GET['oauth_token']) && !$_SESSION['state']) 
        {           
            $request_token_info = $oauth->getRequestToken($req_url,$callback_url);
            $_SESSION['secret'] = $request_token_info['oauth_token_secret'];
            $_SESSION['state'] = 1;
            header('Location: '.$authurl.'?oauth_token='.$request_token_info['oauth_token']);
            exit;
        } 
        else if($_SESSION['state']==1) 
        {
            $oauth->setToken($_GET['oauth_token'],$_SESSION['secret']);
            $access_token_info = $oauth->getAccessToken($acc_url);  //fails here
            $_SESSION['state'] = 2;
            $_SESSION['token'] = $access_token_info['oauth_token'];
            $_SESSION['secret'] = $access_token_info['oauth_token_secret'];
        }
        $oauth->setToken($_SESSION['token'],$_SESSION['secret']);

        if($_SESSION['state']==2)
        {
            //Get the info and do stuff
        }
    } 
    catch(OAuthException $E) 
    {
        print_r($E);
    }
}
?>

0 个答案:

没有答案