2012-04-12 47 views
1

我正在嘗試使用oath2規範爲Google的「服務帳戶」身份驗證形成一個json請求進行身份驗證。我正在使用谷歌的文檔here。它使用JWT。似乎沒有太多有關如何使用C#執行此操作的信息。這是我正在使用的RAW json請求,但我可以從google獲得的唯一回復是「invalid_request」。OAuth2「Google服務」身份驗證返回「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服務,以設定的時間間隔ping谷歌緯度位置?是否有另一種方式可以在不跳過這個圈的情況下訪問該API?謝謝!

+0

,顯然我更換「智威湯遜(包括簽名)」我自己的計算令牌 – aceinthehole 2012-04-12 23:42:47

+0

看起來不喜歡符合「application/x-www-form-urlencoded」的內容。這是json。 – spender 2012-04-13 00:37:01

回答

1

該文檔相對清晰,您應該發佈一個urlencoded字符串。相反,嘗試發佈JSON,後應用程序/ x-WWW窗體-urlencoded數據,而不是:

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