400 Error “error_description” : “Invalid grant_type: urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer” Google Service account

StackOverflow https://stackoverflow.com//questions/24016564

문제

I am following this tutorial https://developers.google.com/accounts/docs/OAuth2ServiceAccount to authorise my application. i have created a JWT by following the tutorial.

But when I make a access token request I keep on getting a "Invalid grant_type: urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer" exception.

Here is my code to make the request

HttpClient httpClient = new HttpClient();
        PostMethod post = new PostMethod("https://accounts.google.com/o/oauth2/token");
        post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        post.addParameter("grant_type", URLEncoder.encode("urn:ietf:params:oauth:grant-type:jwt-bearer", "UTF-8"));
        post.addParameter("assertion", "JWT including signature.");
        httpClient.executeMethod(post);

I have looked at a lot of resources bu the obvious error seems to be mistaking the client id for the email id. However, I have checked and re-cheeked that to make sure that I am using the correct one.

Please can anyone tell me what am I doing wrong.

Many Thanks

도움이 되었습니까?

해결책

I solved it by referring to this post: Invalid grant error is being thrown while retrieving accessToken for Google Service account request.

Turns out that there was a problem with the NTP(Network Time Protocol). The expiration time and the Issued at time had to be changed. After I did that, it start to work properly.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top