Details
-
Type: Monitor
-
Status: Closed
-
Priority: Major
-
Resolution: Done
-
Affects Version/s: None
-
Fix Version/s: 2021
-
Component/s: FIWARE-TECH-HELP
-
Labels:
-
HD-Chapter:Apps
-
HD-Enabler:Wirecloud
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"]))
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.
2017-05-29 00:05|CREATED monitor | # answers= 1, accepted answer= True