首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Clio api在php中与OAuth-2集成

Clio api在php中与OAuth-2集成
EN

Stack Overflow用户
提问于 2018-12-18 22:05:29
回答 1查看 420关注 0票数 0

为了在OAuth中使用Clio api,任何人都可以建议或分享如何使用php 2的代码。

我得到了client_id和client_secret部分。

EN

回答 1

Stack Overflow用户

发布于 2018-12-21 19:59:00

代码语言:javascript
复制
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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53834782

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档