Reputation: 5222
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)"
}
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!
Upvotes: 1
Views: 1540
Reputation: 120450
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
Upvotes: 1