Details
-
Type: Monitor
-
Status: Closed
-
Priority: Major
-
Resolution: Done
-
Affects Version/s: None
-
Fix Version/s: 2021
-
Component/s: FIWARE-TECH-HELP
-
HD-Chapter:Security
-
HD-Enabler:KeyRock
Description
Created question in FIWARE Q/A platform on 15-08-2015 at 09:08
Please, ANSWER this question AT https://stackoverflow.com/questions/32022622/fi-ware-idm-oauth2-php-client-configuration
Question:
Fi-ware IDM - Oauth2 php client configuration
Description:
I'm trying to use the FiWare Identity Management - KeyRock that provides a Oauth 2.0 login. I have configured my app in the Fiware web page to set the url and callback url and I have got my client ID and my password.
Now I'm trying to use the API with a simple PHP client Oauth2.0 library. I've choosen this. It looks very easy to use, but I have a problem:
When I open my web, I'm correctly redirected to the fi-ware login web page, but once i logged, I'm not redirected to my web page callback page, I continue in the fi-ware labs web page.
That's my code:
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();
and 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()));
}
Activity
Field | Original Value | New Value |
---|---|---|
Component/s | FIWARE-TECH-HELP [ 10278 ] |
Status | Open [ 1 ] | In Progress [ 3 ] |
Status | In Progress [ 3 ] | Answered [ 10104 ] |
Assignee | Alvaro Alonso [ aalonsog ] |
HD-Enabler | KeyRock [ 10889 ] | |
HD-Chapter | Security [ 10841 ] |
Resolution | Done [ 10000 ] | |
Status | Answered [ 10104 ] | Closed [ 6 ] |
Fix Version/s | 2021 [ 12600 ] |