OAuth2认证为"谷歌服务"回报" INVALID_REQUEST" [英] OAuth2 Authentication for "Google Service" returns "invalid_request"

查看:211
本文介绍了OAuth2认证为"谷歌服务"回报" INVALID_REQUEST"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图形成一个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

这篇关于OAuth2认证为"谷歌服务"回报" INVALID_REQUEST"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆