为 Hybridauth 提供商 (WordPress) 设置自定义端点时遇到问题

Having trouble setting custom endpoints for Hybridauth provider (WordPress)

我正在尝试使用 Hybridauth(第 3 版)获取经过身份验证的用户的 WordPress 博客列表,使用 https://public-api.wordpress.com/rest/v1.1/me/sites endpoint. Figured out that in order to do so, I need to change the default authorize_url endpoint for WordPress from https://public-api.wordpress.com/oauth2/authenticate to https://public-api.wordpress.com/oauth2/authorize

Hybridauth 允许您更改端点,如此处的示例所示:https://github.com/hybridauth/hybridauth/blob/master/examples/example_03.php

不幸的是,这会导致以下错误:

Fatal error: Uncaught TypeError: Argument 1 passed to Hybridauth\Adapter\AbstractAdapter::setApiEndpoints() must be an instance of Hybridauth\Data\Collection, array given

代码:

$config = [
    "callback"      => APP_URL."/callback", 
    "keys"          => array("id" => "XXXXXX", "secret" => "YYYYYYYYYY"),
    "scope"         => array("global", "auth"),
    "endpoints"     => [
        "authorize_url"    => "https://public-api.wordpress.com/oauth2/authorize",
    ]
];

$adapter = new Hybridauth\Provider\WordPress($config);

我做错了什么?我觉得我错过了一些非常明显的东西。

端点应该是 Hybridauth\Data\Collection.

的一个实例

您可以将当前端点数组值传递给 Hybridauth\Data\Collection 构造函数以创建实例并将其设置为配置数组中的端点键。

<?php

include './vendor/autoload.php';


$endpoints = new Hybridauth\Data\Collection([
    'api_base_url'     => 'https://public-api.wordpress.com/rest/v1.1/',
    'authorize_url'    => 'https://public-api.wordpress.com/oauth2/authorize',
    'access_token_url' => 'https://public-api.wordpress.com/oauth2/token',
]);

$config = [
    'callback'  => Hybridauth\HttpClient\Util::getCurrentUrl(),
    'keys'      => [ 'id' => 'client-id', 'secret' => 'client-secret' ],
    'endpoints' => $endpoints
];

try {
    $adapter = new Hybridauth\Provider\WordPress( $config );
    $adapter->authenticate();

    $tokens = $adapter->getAccessToken();
    print_r($tokens);

    $userProfile = $adapter->getUserProfile();
    print_r( $userProfile );

    $adapter->disconnect();
}
catch (Exception $e) {
    echo $e->getMessage();
}