Clio API与PHP中的OAuth-2集成

时间:2018-12-18 14:05:29

标签: oauth-2.0 clio-api

任何人建议或共享代码如何使用OAuth 2以便在php中使用Clio api。

我有client_id和client_secret部分。

1 个答案:

答案 0 :(得分:0)

protected $app_key = '';
protected $app_secret = '';
protected $authorozation_endpoint = 'https://app.clio.com/oauth/authorize';
protected $deauthorozation_endpoint = 'https://app.clio.com/oauth/deauthorize';
protected $token_endpoint = 'https://app.clio.com/oauth/token';
protected $api_uri = 'https://app.clio.com/api/v4/';

$this->client = new OAuth2\Client($this->app_key, $this->app_secret);

if (!isset($_GET['code'])){
            $auth_url = $this->client->getAuthenticationUrl($this->authorozation_endpoint, $this->redirect_uri);
            header('Location: ' . $auth_url);
            die('Redirect');
    } else {
            $params = array(
                'code' => $_GET['code'],
                'redirect_uri' => $this->redirect_uri,
                'client_id' => $this->app_key
                );
            $response = $this->client->getAccessToken($this->token_endpoint, 'authorization_code', $params);
            if (isset($response['result']) && is_array($response['result'])){
                if (isset($response['result']['access_token'])){$this->access_token = $response['result']['access_token'];}
                if (isset($response['result']['refresh_token'])){$this->refresh_token = $response['result']['refresh_token'];}
                if (isset($response['result']['token_type'])){$this->access_token_type = $response['result']['token_type'];}
            }
            if (!$this->access_token){
                $this->log .= __METHOD__. ' no access token ';
                return false;
            }
            $this->client->setAccessToken($this->access_token);