0

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

我得到了 client_id 和 client_secret 部分。

4

1 回答 1

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);
于 2018-12-21T11:58:59.527 回答