简体   繁体   中英

Account linking error: "Can't parse the response. The response needs to be JSON format."

I am attempting account linking within 'Actions on Google'. Everything works until my OAuth provider responds to Google's request for tokens.

This is the JSON that is returned and appears to be properly formatted:

{"access_token":"edeaa27e-12b7-43a1-bc7c-e6bbf9af71c3","expires_in":5184000.0,"refresh_token":"4344383b-cf07-4d12-a5c2-44b6481f5f48","token_type":"Bearer"}

This is the error:

{ "@type": "type.googleapis.com/google.identity.accountlinking.type.AccountLinkingError", "errorReason": "Can't parse the response. The response needs to be JSON format.", "response": { ... }, "step": "AUTH_CODE_EXCHANGE" }

Details:

{
  "insertId": "-hgv4mfb4b",
  "jsonPayload": {
    "@type": "type.googleapis.com/google.identity.accountlinking.type.AccountLinkingError",
    "errorReason": "Can't parse the response. The response needs to be JSON format.",
    "response": {
      "status": 200,
      "body": "{\"access_token\":\"cdd79134-316d-46ca-8d82-62fc7c35d905\",\"expires_in\":5184000.0,\"refresh_token\":\"fc63ceb3-0a8d-40ac-a1a3-a8cfab110bef\",\"token_type\":\"Bearer\"}"
    },
    "step": "AUTH_CODE_EXCHANGE"
  },
  "resource": {
    "type": "assistant_action_project",
    "labels": {
      "project_id": "my-project"
    }
  },
  "timestamp": "2021-07-30T23:15:28.221Z",
  "severity": "ERROR",
  "logName": "projects/my-project/logs/accountlinking-pa.googleapis.com%2Ferror",
  "receiveTimestamp": "2021-07-30T23:15:28.676796217Z"
}

Here is the response from my OAuth provider via curl. This is what Google gets. It looks like properly formatted JSON.

< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Cache-Control: private
Cache-Control: private
< Content-Type: application/json; charset=utf-8
Content-Type: application/json; charset=utf-8
< Vary: Accept
Vary: Accept
< Server: Microsoft-IIS/8.5
Server: Microsoft-IIS/8.5
< Request-Context: appId=cid-v1:f494398c-ac65-47c8-84be-65aea2c190a4
Request-Context: appId=cid-v1:f494398c-ac65-47c8-84be-65aea2c190a4
< X-HOST-nonce: 3eTaf/2/7riVVh24uAsUT+KHqcJPq0F2cw7C5ldMkMF4iH5rDbHQEgOp2OU9RaQFr/HjBBEpkKekcCxlmzek5g==
X-HOST-nonce: 3eTaf/2/7riVVh24uAsUT+KHqcJPq0F2cw7C5ldMkMF4iH5rDbHQEgOp2OU9RaQFr/HjBBEpkKekcCxlmzek5g==
< X-Powered-By: ServiceStack/4.040 Win32NT/.NET
X-Powered-By: ServiceStack/4.040 Win32NT/.NET
< X-AspNet-Version: 4.0.30319
X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
< Date: Tue, 03 Aug 2021 03:17:00 GMT
Date: Tue, 03 Aug 2021 03:17:00 GMT
< Content-Length: 155
Content-Length: 155
< x-HOST-proxy: true
x-HOST-proxy: true
< Strict-Transport-Security: max-age=15768000
Strict-Transport-Security: max-age=15768000

{"access_token":"6cff16ee-3b3e-4ecf-9664-51515ede6cc8","expires_in":5184000.0,"refresh_token":"03725df6-8d4c-434a-ab36-adedb43b76d7","token_type":"Bearer"}

Google will not accept the 'expires_in' value above, because it includes a decimal. Not sure if this impacts all values with a decimal or just '.0', but the OAuth spec doesn't seem to specifically exclude such a value. Javascript converts any float with just a 0 after the decimal to a whole number. My issue was that the 3rd party OAuth provider was returning a string including a float that Google would not parse as JSON.

I don't want to ask another question and I can't comment, so I am writing in answer :). I have exactly the same error message in the same situation. I have clear int value and it doesn't work. If you could help I will be grateful :)

My JSON response: {"token_type":"Bearer","access_token":"jkljkhasdjhjhkdhasdsd","refresh_token":"jkljkhasdjhjhkdhasdsf","expires_in":86400}

What's wrong with that answer?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM