小编FuF*_*uFu的帖子

如何在 PHP 中获取 OAuth 2.0 令牌?

我需要连接到客户的 REST API。第一步是获取 OAuth 2.0 访问令牌。我从客户那里得到以下信息:

  • 登录(我认为是client_id
  • 密码(我假设是client_secret
  • 流量是 password
  • 常规 API URL
  • 令牌 API 网址

我在http://tutorialspage.com/simple-oauth2-example-using-php-curl/找到了代码 并将其更改为仅用于测试:

private function getToken() {

    $curl = curl_init();

    $params = array(
        CURLOPT_URL =>  self::API_TOKEN_URL,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_POST => 1,
        CURLOPT_NOBODY => false,
        CURLOPT_HTTPHEADER => array(
            "cache-control: no-cache",
            "content-type: application/x-www-form-urlencoded",
            "accept: *",
            "accept-encoding: gzip, deflate",
        ),
        CURLOPT_POSTFIELDS => array(
            'username' => urlencode('example@swagger.foo'),
            'password' => urlencode('123 and 4'),
            'grant_type' => 'password'
        ) …
Run Code Online (Sandbox Code Playgroud)

php oauth-2.0

1
推荐指数
1
解决办法
3193
查看次数

标签 统计

oauth-2.0 ×1

php ×1