Google OAuth2 Service Account Access Token Request gives 'Invalid Request' Response

前端 未结 2 1073
有刺的猬
有刺的猬 2020-12-05 20:23

I\'m trying to communicate with my app\'s enabled BigQuery API via the server to server method.

I\'ve ticked all the boxes on this Google guide for constructing my J

相关标签:
2条回答
  • 2020-12-05 20:31

    Be sure to use DateTime.UtcNow instead of DateTime.Now in the GetExpiryAndIssueDate method.

    0 讨论(0)
  • 2020-12-05 20:51

    Looks like my guess in the comment above was correct. I got your code working by changing:

    "urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer"

    to:

    "urn:ietf:params:oauth:grant-type:jwt-bearer"

    Looks like you were accidentally double-encoding it.

    I now get a response which looks something like:

    {
      "access_token" : "1/_5pUwJZs9a545HSeXXXXXuNGITp1XtHhZXXxxyyaacqkbc",
      "token_type" : "Bearer",
      "expires_in" : 3600
    }
    

    Edited Note: please make sure to have the correct date/time/timezone/dst configuration on your server. Having the clock off by even a few seconds will result in an invalid_grant error. http://www.time.gov will give the official time from the US govt, including in UTC.

    0 讨论(0)
提交回复
热议问题