[英]How do I get token from fiware lab to access context broker placed behind PeP proxy?
I tried to use the logic of this curl command: 我试图使用curl命令的逻辑:
curl -s --insecure -i --header ${AUTH_BASIC} --header ${CONTENT_TYPE} -X POST https://idm/oauth2/token -d ${DATA}"
XAUTH_TOKEN="$(eval ${REQUEST} | grep -Po '(?<="access_token": ")[^"]*')"
echo "X-Auth-Token for '${_user}': ${XAUTH_TOKEN}
to write the request in c#: 用C#编写请求:
//GETTING TOKEN...
String input2 = "'grant_type=password&username=<MyUsername on Lab .fiware.org&password=<myPassword>&client_id=<myClientID>&client_secret=<myClientSecret>'";
var httpWebRequest2 = (HttpWebRequest)WebRequest.Create("https://account.lab.fiware.org/oauth2/token");
httpWebRequest2.ContentType = "application/x-www-form-urlencoded";
//httpWebRequest2.Accept = "application/json";
string authInfo = "0555996e09f340d08a4baa8fff94f8c4" + ":" + "a62333f7045b4ab797669c28f9d26d30";
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
httpWebRequest2.Headers["Authorization"] = "Basic " + authInfo;
httpWebRequest2.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest2.GetRequestStream()))
{
streamWriter.Write(input2);
streamWriter.Flush();
streamWriter.Close();
}
var httpResponse2 = (HttpWebResponse)httpWebRequest2.GetResponse();
using (var streamReader = new StreamReader(httpResponse2.GetResponseStream()))
{
string result = streamReader.ReadToEnd();
Console.WriteLine(result);
}
But I get the following error: 但是我收到以下错误:
When I tried doing this solution in localhost, like in the post here it works without a problem. 当我尝试在localhost中执行此解决方案时,如此处的帖子所述,它可以正常工作。 Could it have anything to do with the fact that I registered the app under localhost:1307 in the lab account?
这与我在实验室帐户中的localhost:1307下注册该应用程序有关吗?
There are not enough details to debug it, but KeyRock returns 400
when the request it's not well formed. 没有足够的细节来调试它,但是如果请求的格式不正确,KeyRock将返回
400
。 You should get the message KeyRock returns. 您应该得到消息KeyRock返回。 Still, with this request, you can get code
400
if: 尽管如此,在以下情况下,仍然可以通过此请求获得代码
400
:
The Authorization: Basic
header is missing, in which case you will get: 缺少
Authorization: Basic
标头,在这种情况下,您将获得:
HTTP/1.1 400 BAD REQUEST Date: Thu, 10 Sep 2015 08:43:25 GMT Server: Apache/2.4.7 (Ubuntu) Vary: Accept-Language,Cookie X-Frame-Options: SAMEORIGIN Content-Language: en Connection: close Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 Authentication header missing. Use HTTP Basic.
The request body (ie your input2
) is not being sent, in which case you will get: 请求正文(即您的
input2
)未发送,在这种情况下,您将获得:
HTTP/1.1 400 Bad Request Date: Thu, 10 Sep 2015 08:47:49 GMT Server: Apache/2.4.7 (Ubuntu) Vary: Accept-Language,Cookie X-Frame-Options: SAMEORIGIN Content-Language: en Connection: close Transfer-Encoding: chunked Content-Type: application/json {"error": {"message": "create_access_token() takes exactly 3 arguments (2 given)", "code": 400, "title": "Bad Request"}}
The grant_type
is not defined in your request body: 在您的请求正文中未定义
grant_type
:
HTTP/1.1 400 Bad Request Date: Thu, 10 Sep 2015 08:52:58 GMT Server: Apache/2.4.7 (Ubuntu) Vary: Accept-Language,Cookie X-Frame-Options: SAMEORIGIN Content-Language: en Connection: close Transfer-Encoding: chunked Content-Type: application/json {"error": {"message": "grant_type missing in request body: {}", "code": 400, "title": "Bad Request"}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.