php - yii2、谷歌 oauth2 和范围

标签 php oauth-2.0 yii2 google-api-php-client yii2-user

我正在使用 Yii2、GoogleOAuth 和 yii2-user 扩展。我想接收用户 google 圈子并将范围设置为我的配置:

'authClientCollection' => [
        'class' => 'yii\authclient\Collection',
        'clients' => [
            'google' => [
                'class' => 'yii\authclient\clients\GoogleOAuth',
                'clientId' => '758709912345-p4qp4lqihit5un1u6qb75msqp5m5j6d8.apps.googleusercontent.com',
                'clientSecret' => 'ZygOIi1-0asfktUQ1pKOFOo',
                'scope' => 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/drive',
            ],
        ],
    ]

当我使用 Google OAuth2 登录时出现错误:

Exception – yii\authclient\InvalidResponseException Request failed with code: 400, message: { "error" : "redirect_uri_mismatch" }

谷歌回应:

[
'url' => 'https://accounts.google.com/o/oauth2/token'
'content_type' => 'application/json'
'http_code' => 400
'header_size' => 435
'request_size' => 644
'filetime' => -1
'ssl_verify_result' => 0
'redirect_count' => 0
'total_time' => 0.115431
'namelookup_time' => 0.001186
'connect_time' => 0.025188
'pretransfer_time' => 0.076275
'size_upload' => 456
'size_download' => 39
'speed_download' => 337
'speed_upload' => 3950
'download_content_length' => -1
'upload_content_length' => 456
'starttransfer_time' => 0.114206
'redirect_time' => 0
'certinfo' => []
'primary_ip' => '2a00:1450:4010:c08::54'
'primary_port' => 443
'local_ip' => '2a03:6f00:1::5c35:726b'
'local_port' => 33160
'redirect_url' => ''

]

当我从配置中删除 Google+ 范围 ( https://www.googleapis.com/auth/plus.login ) 授权时,没有错误,谷歌的响应是:

[
'url' => 'https://accounts.google.com/o/oauth2/token'
'content_type' => 'application/json; charset=utf-8'
'http_code' => 200
'header_size' => 522
'request_size' => 526
'filetime' => -1
'ssl_verify_result' => 0
'redirect_count' => 0
'total_time' => 0.13719
'namelookup_time' => 0.001212
'connect_time' => 0.026261
'pretransfer_time' => 0.079765
'size_upload' => 338
'size_download' => 900
'speed_download' => 6560
'speed_upload' => 2463
'download_content_length' => -1
'upload_content_length' => 338
'starttransfer_time' => 0.136241
'redirect_time' => 0
'certinfo' => []
'primary_ip' => '2a00:1450:4010:c08::54'
'primary_port' => 443
'local_ip' => '2a03:6f00:1::5c35:726b'
'local_port' => 37583
'redirect_url' => ''

]

问题仅在 https://www.googleapis.com/auth/plus.login 中。我启用的 API:http://minus.com/lJ5nw7caXJApD

最佳答案

您还可以在您的身份验证客户端配置中显式添加 returnUrl。看docs了解更多信息。

关于php - yii2、谷歌 oauth2 和范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28829798/

相关文章:

javascript - Yii2 - 在 GridView 中使用 Ajax/Pjax 通过 switch toogle 更新数据

php - 从 MySQL 表并发获取任务

php - DOMPDF 安装选项

Azure OAuth2 代码流,组声明不在访问 token 中,而是在 id token 中

android - 在未经用户同意的情况下处理 Android 中过期的访问 token

jquery - Yii2:如何打开 GridView 的列标题?

yii2 - 是否可以在某个时间完成 Beanstalkd 任务?

php - 添加评论后,字母出现在 php 站点的评论框中。如何限制每行显示的字母?

php - 使用 data-tooltip 元素格式化 CSS

c# - Paypal API 登录停止工作