Uploaded image for project: 'Help-Desk'
  1. Help-Desk
  2. HELP-9190

[fiware-stackoverflow] Fi-ware IDM - Oauth2 php cliente configuration

    Details

      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-cliente-configuration

      Question:
      Fi-ware IDM - Oauth2 php cliente 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

        Hide
        backlogmanager Backlog Manager added a comment -

        2017-05-24 09:05|CREATED monitor | # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2017-05-24 09:05|CREATED monitor | # answers= 1, accepted answer= True
        Hide
        backlogmanager Backlog Manager added a comment -

        2017-05-24 12:05|UPDATED status: transition Answer| # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2017-05-24 12:05|UPDATED status: transition Answer| # answers= 1, accepted answer= True
        Hide
        backlogmanager Backlog Manager added a comment -

        2017-05-24 15:05|UPDATED status: transition Answered| # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2017-05-24 15:05|UPDATED status: transition Answered| # answers= 1, accepted answer= True

          People

          • Assignee:
            aalonsog Alvaro Alonso
            Reporter:
            backlogmanager Backlog Manager
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: