Google行动:帐户关联将GET请求发送到令牌URL

时间:2019-03-26 11:49:09

标签: actions-on-google

我在与Google Actions的帐户关联方面遇到一些问题:

我已经实现了Google文档中描述的OAuth2步骤。我已经实现了OAuth2服务器并通过Postman对其进行了测试,并且能够按预期获得访问令牌。

如果我尝试通过将服务添加到我的帐户来从Google Home应用进行身份验证,则会进入授权表单,授权工作正常,并按照预期的方式对Google的重定向URI进行授权代码响应。但是Google返回的URI提示“帐户链接失败”,然后我在Google Home应用中收到一条消息:“无法更新设置。检查您的连接”。

我在记录令牌URL脚本时看到的另一件奇怪的事:我可以看到从Google到令牌URL的传入GET请求,而不是带有Google文档中提到的必需数据的POST请求。因此,即使出现“帐户链接失败”消息,似乎Google也在调用我的令牌URL,但使用的是GET而不是POST。

以下是对令牌URL的请求日志:

从POSTMAN请求(测试软件)>确定

__SERVER
Array
(
    [USER] => www-data
    [HOME] => /var/www
    [HTTP_ACCEPT_ENCODING] => gzip, deflate
    [HTTP_ACCEPT] => */*
    [HTTP_USER_AGENT] => PostmanRuntime/7.6.1
    [HTTP_POSTMAN_TOKEN] => f85664e2-7d38-4511-9519-cddda3feec06
    [HTTP_CACHE_CONTROL] => no-cache
    [HTTP_CONTENT_TYPE] => application/x-www-form-urlencoded
    [HTTP_CONTENT_LENGTH] => 145
    [HTTP_CONNECTION] => close
    [HTTP_HOST] => 127.0.0.1
    [REDIRECT_STATUS] => 200
    [SERVER_NAME] => _
    [SERVER_PORT] => 80
    [SERVER_ADDR] => 127.0.0.1
    [REMOTE_PORT] => 38622
    [REMOTE_ADDR] => 127.0.0.1
    [SERVER_SOFTWARE] => nginx/1.12.2
    [GATEWAY_INTERFACE] => CGI/1.1
    [REQUEST_SCHEME] => http
    [SERVER_PROTOCOL] => HTTP/1.0
    [DOCUMENT_ROOT] => [******]
    [DOCUMENT_URI] => /google/token/index.php
    [REQUEST_URI] => /google/token/
    [SCRIPT_NAME] => /google/token/index.php
    [CONTENT_LENGTH] => 145
    [CONTENT_TYPE] => application/x-www-form-urlencoded
    [REQUEST_METHOD] => POST
    [QUERY_STRING] =>
    [SCRIPT_FILENAME] => [******]
    [FCGI_ROLE] => RESPONDER
    [PHP_SELF] => /google/token/index.php
    [REQUEST_TIME_FLOAT] => 1553765980.9273
    [REQUEST_TIME] => 1553765980
)
__POST
Array
(
    [client_id] => [******]
    [client_secret] => [******]
    [grant_type] => authorization_code
    [code] => [******]
)

在智能手机上使用GOOGLE HOME APP进行测试时收到请求>不确定

__SERVER
Array
(
    [USER] => www-data
    [HOME] => /var/www
    [HTTP_ACCEPT_ENCODING] => gzip,deflate,br
    [HTTP_USER_AGENT] => OpenAuth
    [HTTP_CONTENT_TYPE] => application/x-www-form-urlencoded
    [HTTP_CONNECTION] => close
    [HTTP_HOST] => 127.0.0.1
    [REDIRECT_STATUS] => 200
    [SERVER_NAME] => _
    [SERVER_PORT] => 80
    [SERVER_ADDR] => 127.0.0.1
    [REMOTE_PORT] => 46184
    [REMOTE_ADDR] => 127.0.0.1
    [SERVER_SOFTWARE] => nginx/1.12.2
    [GATEWAY_INTERFACE] => CGI/1.1
    [REQUEST_SCHEME] => http
    [SERVER_PROTOCOL] => HTTP/1.0
    [DOCUMENT_ROOT] => [******]
    [DOCUMENT_URI] => /google/token/index.php
    [REQUEST_URI] => /google/token/
    [SCRIPT_NAME] => /google/token/index.php
    [CONTENT_LENGTH] =>
    [CONTENT_TYPE] => application/x-www-form-urlencoded
    [REQUEST_METHOD] => GET
    [QUERY_STRING] =>
    [SCRIPT_FILENAME] => [******]
    [FCGI_ROLE] => RESPONDER
    [PHP_SELF] => /google/token/index.php
    [REQUEST_TIME_FLOAT] => 1553767309.7797
    [REQUEST_TIME] => 1553767309
)
__REQUEST
Array
(
)
__POST
Array
(
)
__GET
Array
(
)
-------------------------
__ANSWER
400: invalid grant

Configuration in Actions Console

1 个答案:

答案 0 :(得分:1)

问题似乎是由/重定向到/index.php而没有POST值引起的。

通过在操作控制台中将我的URL更改为/index.php来解决此问题,现在链接可以正常工作了。