如何通过授予密码获取访问令牌?

时间:2019-06-19 03:29:40

标签: php wordpress oauth-2.0

我收到响应“试图获取非对象的属性'access_token'”

我需要使用Oauth2协议连接到我的网站。

我会遵循发现的所有内容,但会得到一些我不理解的结果。

首先。

环境是用于测试目的的localhost。之前,我是现场直播的。而wordpress是最新的5.2.1

  1. 我将wordpress安装到我的虚拟主机上。
  2. 我从官方wordpress github将Oauth2插件安装到我的wordpres中。
  3. 我通过wordpress注册应用程序。
  4. 我获得了客户端ID和客户端密码。我将回调网址设置为localhost
<?php
$curl = curl_init( 'https://localhost/oauth2/token' );
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36');
curl_setopt( $curl, CURLOPT_POSTFIELDS, array(
    'client_id' => 'dpaxxoptvane',
    'client_secret' => 'FxOPFrNKCiVJqrD7bnMpume3CL98PfsJFUa7qDWK1XVPars3',
    'grant_type' => 'password',
    'username' => 'admin',
    'password' => 'admin',
) );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);
$auth = curl_exec( $curl );
$auth = json_decode($auth);
$access_key = $auth->access_token;

echo $access_key
?>

0 个答案:

没有答案
相关问题