wi -ware IDM - Oauth2 php客户端配置


Fi-ware IDM - Oauth2 php client configuration

我正在尝试使用提供Oauth 2.0登录的FiWare身份管理- KeyRock。我已经在Fiware网页中配置了我的应用程序来设置url和回调url,我已经得到了我的客户端ID和密码。

现在我试图使用API与一个简单的PHP客户端Oauth2.0库。我选择了这个。它看起来很容易使用,但我有一个问题:

当我打开我的网页时,我被正确地重定向到fi-ware登录网页,但一旦我登录,我没有重定向到我的网页回调页面,我继续在fi-ware实验室网页。

这是我的代码:

index . php:

<?php
require_once 'vendor/autoload.php';
use fkooman'OAuth'Client'Guzzle6Client;
use fkooman'OAuth'Client'ClientConfig;
use fkooman'OAuth'Client'SessionStorage;
use fkooman'OAuth'Client'Api;
use fkooman'OAuth'Client'Context;
$clientConfig = new ClientConfig(
    array(
        'authorize_endpoint' => 'https://account.lab.fi-ware.org',
        'client_id' => 'my_client_id',
        'client_secret' => 'my_secret',
        'token_endpoint' => 'http://estebanxabi.miwp.eu/otros/callback.php',
    )
);
$tokenStorage = new SessionStorage();
$httpClient = new Guzzle6Client();
$api = new Api('foo', $clientConfig, $tokenStorage, $httpClient);
$context = new Context('sampleEmail', array('authorizations'));
$accessToken = $api->getAccessToken($context);
if (false === $accessToken) {
    /* no valid access token available, go to authorization server */
    header('HTTP/1.1 302 Found');
    header('Location: '.$api->getAuthorizeUri($context));
    exit;
}
echo 'Access Token: '.$accessToken->getAccessToken();

和callback.php:

<?php
require_once 'vendor/autoload.php';
use fkooman'OAuth'Client'Guzzle6Client;
use fkooman'OAuth'Client'ClientConfig;
use fkooman'OAuth'Client'SessionStorage;
use fkooman'OAuth'Client'Callback;
$clientConfig = new ClientConfig(
    array(
        'authorize_endpoint' => 'https://account.lab.fi-ware.org',
        'client_id' => 'client_ide',
        'client_secret' => 'seceret',
        'token_endpoint' => 'http://estebanxabi.miwp.eu/otros/callback.php',
    )
);
try {
    $tokenStorage = new SessionStorage();
    $httpClient = new Guzzle6Client();
    $cb = new Callback('foo', $clientConfig, $tokenStorage, $httpClient);
    $cb->handleCallback($_GET);
    header('HTTP/1.1 302 Found');
    header('Location: http://localhost/fkooman/php-oauth-client/example/simple6/index.php');
    exit;
} catch (fkooman'OAuth'Client'Exception'AuthorizeException $e) {
    // this exception is thrown by Callback when the OAuth server returns a
    // specific error message for the client, e.g.: the user did not authorize
    // the request
    die(sprintf('ERROR: %s, DESCRIPTION: %s', $e->getMessage(), $e->getDescription()));
} catch (Exception $e) {
    // other error, these should never occur in the normal flow
    die(sprintf('ERROR: %s', $e->getMessage()));
}

我从来没有使用过这个库,但是看看…您确定"token_endpoint"配置正确吗?令牌端点(/oauth2/token)与回调URL不同。

BR