我试图形成一个JSON请求使用oath2规范谷歌的服务帐户身份验证来验证。我使用谷歌的文档这里。它是使用JWT。似乎没有对如何做到这一点使用C#的信息。这是我现在用的是原始JSON请求,但我可以从谷歌得到的唯一回应是INVALID_REQUEST。
I am attempting to form a json request to authenticate using oath2 specification for Google's "Service Account" authentication. I am using google's documentation here. It is using JWT. It seems that there is not much information on how to do this using C#. This is the RAW json request that I am using, but the only response I can get from google is "invalid_request".
POST https://accounts.google.com/o/oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: accounts.google.com
Content-Length: 457
Expect: 100-continue
Connection: Keep-Alive
{
"grant_type": "assertion",
"assertion_type": "http://oauth.net/grant_type/jwt/1.0/bearer",
"assertion": "JWT (including signature)"
}
这是什么可以去任何想法?我试图创建一个Windows服务坪谷歌纬度位置在设定的时间间隔?是否有潜在的另一种方式来获得访问该API,而通过这个箍跳?谢谢!
Any ideas on what could be going on? I am attempting to create a windows service that pings google latitude locations at set intervals? Is there potentially another way to get access to that API without jumping through this hoop? Thanks!
推荐答案
该文档是比较清楚的,你应该张贴urlen codeD字符串。而是试图张贴JSON,后期应用程序/ x-WWW的形式urlen codeD数据,而不是:
The docs are relatively clear that you should POST a urlencoded string. Instead of attempting to post json, post application/x-www-form-urlencoded data instead:
var invariantPart = "grant_type=assertion&" +
"assertion_type=http%3A%2F%2Foauth.net%2Fgrant_type%2Fjwt%2F1.0%2Fbearer&" +
"assertion=";
var fullPostData = invariantPart + Uri.EscapeDataString(myCalculatedAssertion);
//POST fullPostData to google
相关推荐
最新文章