Fi-ware IDM - Oauth2 php客户端配置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Fi-ware IDM - Oauth2 php客户端配置相关的知识,希望对你有一定的参考价值。
我正在尝试使用提供Oauth 2.0登录的FiWare Identity Management - KeyRock。我在Fiware网页中配置了我的应用程序来设置网址和回调网址,我有我的客户端ID和密码。
现在我正在尝试将API与简单的php客户端Oauth2.0库一起使用。我选择了this。它看起来很容易使用,但我有一个问题:
当我打开我的网页时,我被正确地重定向到了fi-ware登录网页,但是一旦我登录,我就没有被重定向到我的网页回调页面,我继续在fi-ware实验室网页上。
那是我的代码:
index.php文件:
<?php
require_once 'vendor/autoload.php';
use fkoomanOAuthClientGuzzle6Client;
use fkoomanOAuthClientClientConfig;
use fkoomanOAuthClientSessionStorage;
use fkoomanOAuthClientApi;
use fkoomanOAuthClientContext;
$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 fkoomanOAuthClientGuzzle6Client;
use fkoomanOAuthClientClientConfig;
use fkoomanOAuthClientSessionStorage;
use fkoomanOAuthClientCallback;
$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 (fkoomanOAuthClientExceptionAuthorizeException $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
以上是关于Fi-ware IDM - Oauth2 php客户端配置的主要内容,如果未能解决你的问题,请参考以下文章