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

[fiware-stackoverflow] how to pass oauth2 token to mashup filab?

    Details

      Description

      Created question in FIWARE Q/A platform on 05-09-2015 at 11:09
      Please, ANSWER this question AT https://stackoverflow.com/questions/32411479/how-to-pass-oauth2-token-to-mashup-filab

      Question:
      how to pass oauth2 token to mashup filab?

      Description:
      I have followed the whole process to obtain an oauth2 access token from the Identity Manager (I get it) and I want to pass it to a web application developed on Filab Mashup but embedded in my own web.
      In my Mashup application I need get the oauth token for to access Orion Context Broker information but I don't know how to pass it.
      This is the code of my callback URL where I obtain the token:

      <?php
      //get the code from url
      $code = $_GET["code"];

      //print_r($code);

      //application specific declarations
      $domain = "www.talkysync.com";
      $clientId = "my_client_ID";
      $clientSecret = "my_client_secret";
      //access token url
      $url = 'https://account.lab.fiware.org/oauth2/token';

      //payload params for the request token
      $payload = 'grant_type=authorization_code&code='. $code .'&redirect_uri=http%3A%2F%2Fwww.talkysync.com%2Ffiware_login%2Fcallback.php';

      //base64(client_id:client_secret)
      $cadena = $clientId . ":" .$clientSecret;
      $base = base64_encode($cadena);

      //extra header for the request
      $header = array("Content-Type: application/x-www-form-urlencoded", "Authorization: Basic ". $base);

      //actual request implementation
      $ch = curl_init($url);

      curl_close($ch);
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      $output = curl_exec($ch);
      ;
      //get the access token from the json response

      $jsonData = json_decode($output,true);
      $access_token = $jsonData["access_token"];

      //start a session and set the access token to it
      session_start();
      $_SESSION["X-Auth-Token"] = $access_token;
      $_SESSION["code"] = $code;

      header("Location: fiware.php");
      ?>

      And this is the code of fiware.php:

      <?php
      session_start();
      if(!isset($_SESSION["X-Auth-Token"]))

      { header('Location: login.php'); }

      else

      { header('Location: https://mashup.lab.fiware.org/ertonio/Talkykar?mode=embedded'); }

      ?>

      But in the mashup application I always have an anonymous connection because I don't know how to pass it the token.

      Thanks in advance.

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open In Progress In Progress
        2h 59m 1 Backlog Manager 29/May/17 3:04 AM
        In Progress In Progress Answered Answered
        2h 59m 1 Backlog Manager 29/May/17 6:04 AM
        Answered Answered Closed Closed
        1h 39m 1 Fernando Lopez 29/May/17 7:44 AM

          People

          • Assignee:
            aarranz Álvaro Arranz
            Reporter:
            backlogmanager Backlog Manager
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: