2

我已经按照整个过程从 Identity Manager 获取 oauth2 访问令牌(我得到了),我想将它传递给在 Filab Mashup 上开发但嵌入到我自己的 Web 中的 Web 应用程序。在我的 Mashup 应用程序中,我需要获取 oauth 令牌才能访问 Orion Context Broker 信息,但我不知道如何传递它。这是我获取令牌的回调 URL 的代码:

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

这是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');
}
?>

但是在混搭应用程序中,我总是有一个匿名连接,因为我不知道如何将令牌传递给它。

提前致谢。

4

1 回答 1

1

目前无法创建包含凭据的嵌入式 WireCloud URL。看起来很有趣,值得实现,但也似乎需要做很多工作,所以不要指望它会在短时间内实现。

关于从 WireCloud 访问 Orion 上下文代理,请查看FIWARE 学院提供的WireCloud 课程中的“3.2.1. 使用 Orion 上下文代理”部分。

于 2015-09-17T09:50:18.500 回答