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

        backlogmanager Backlog Manager created issue -
        backlogmanager Backlog Manager made changes -
        Field Original Value New Value
        Component/s FIWARE-TECH-HELP [ 10278 ]
        backlogmanager Backlog Manager made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        backlogmanager Backlog Manager made changes -
        Status In Progress [ 3 ] Answered [ 10104 ]
        fla Fernando Lopez made changes -
        Assignee Álvaro Arranz [ aarranz ]
        fla Fernando Lopez made changes -
        HD-Enabler Wirecloud [ 10857 ]
        Description
        Created question in FIWARE Q/A platform on 05-09-2015 at 11:09
        {color: red}Please, ANSWER this question AT{color} 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:

        &lt;?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&#39;;

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

        //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");
        ?&gt;


        And this is the code of fiware.php:

        &lt;?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&#39;);
        }
        ?&gt;


        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.
        Created question in FIWARE Q/A platform on 05-09-2015 at 11:09
        {color: red}Please, ANSWER this question AT{color} 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:

        &lt;?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&#39;;

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

        //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");
        ?&gt;


        And this is the code of fiware.php:

        &lt;?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&#39;);
        }
        ?&gt;


        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.
        HD-Chapter Apps [ 10836 ]
        fla Fernando Lopez made changes -
        Resolution Done [ 10000 ]
        Status Answered [ 10104 ] Closed [ 6 ]
        fla Fernando Lopez made changes -
        Fix Version/s 2021 [ 12600 ]

          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: