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

[fiware-stackoverflow] Fi-ware IDM - Oauth2 php client 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-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

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open In Progress In Progress
        2h 59m 1 Backlog Manager 16/Jan/18 9:05 PM
        In Progress In Progress Answered Answered
        3h 1 Backlog Manager 17/Jan/18 12:06 AM
        Answered Answered Closed Closed
        7d 11h 57m 1 Alvaro Alonso 24/Jan/18 12:03 PM
        fla Fernando Lopez made changes -
        Fix Version/s 2021 [ 12600 ]
        aalonsog Alvaro Alonso made changes -
        Resolution Done [ 10000 ]
        Status Answered [ 10104 ] Closed [ 6 ]
        fla Fernando Lopez made changes -
        HD-Enabler KeyRock [ 10889 ]
        HD-Chapter Security [ 10841 ]
        fla Fernando Lopez made changes -
        Assignee Alvaro Alonso [ aalonsog ]
        Hide
        backlogmanager Backlog Manager added a comment -

        2018-01-17 00:06|UPDATED status: transition Answered| # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2018-01-17 00:06|UPDATED status: transition Answered| # answers= 1, accepted answer= True
        backlogmanager Backlog Manager made changes -
        Status In Progress [ 3 ] Answered [ 10104 ]
        Hide
        backlogmanager Backlog Manager added a comment -

        2018-01-16 21:05|UPDATED status: transition Answer| # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2018-01-16 21:05|UPDATED status: transition Answer| # answers= 1, accepted answer= True
        backlogmanager Backlog Manager made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        backlogmanager Backlog Manager made changes -
        Field Original Value New Value
        Component/s FIWARE-TECH-HELP [ 10278 ]
        Hide
        backlogmanager Backlog Manager added a comment -

        2018-01-16 18:06|CREATED monitor | # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2018-01-16 18:06|CREATED monitor | # answers= 1, accepted answer= True
        backlogmanager Backlog Manager created issue -

          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: