php - Google OAuth 屏幕:我需要验证吗?
问题描述
我在我的网站上申请 Google 身份验证已经 7 周了。我仍然看到“正在验证”,而且我从未收到任何来自 Google 支持的电子邮件。我检查了一切。我的开发人员电子邮件在那里,系统符合所有规则。但还是一无所获。
不过,我注意到一件事:我已在 7 周前将发布状态更改为“生产中”,并且我注册了 2 个新帐户。但是“OAuth 用户上限”仍然是(4/100),因为它处于测试模式。据我了解,此“用户上限”仅在请求敏感数据时使用。那正确吗?
所以问题是:如果我只使用用户电子邮件、姓名和个人资料图片进行 Google 身份验证,我是否真的需要验证应用程序?或者在我的情况下不需要,我可以简单地开始获得新的注册?
这是我使用的代码:
require_once 'vendor/autoload.php';
// init configuration
$clientID = 'myclientid.apps.googleusercontent.com';
$clientSecret = 'my_client_secret';
$redirectUri = 'https://somesite.com/'.$this->w->lang.'/authorise';
$googleLoginLink = false;
// create Client Request to access Google API
$client = new Google_Client();
$client->setClientId($clientID);
$client->setClientSecret($clientSecret);
$client->setRedirectUri($redirectUri);
$client->addScope("email");
$client->addScope("profile");
if (isset($_GET['code'])) {
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);//get token
if(isset($token['error'])){//error handling should be done here
echo 'Invalid token';
$googleLoginLink = $client->createAuthUrl();//get login link
}
else{
$client->setAccessToken($token['access_token']);
// get profile info
$google_oauth = new Google_Service_Oauth2($client);
$google_account_info = $google_oauth->userinfo->get();
$email = $google_account_info->email;
$name = $google_account_info->name;
$icon = $google_account_info->picture;
$check = $this->db->numrows('users', array('email'=>$email));//check if user already exists
if($check){
//here I sign in the user
}
else{
//here I sign up the user using data from variables above
}
header('Location: /en/users/profile/personal');
return;
}
}
else{
$googleLoginLink = $client->createAuthUrl();
}
if($googleLoginLink){//show login link
echo '<a href="'.$googleLoginLink.'">Google login</a>';
}
PS 我会提供该项目的链接,但我不确定它是否会被视为垃圾邮件。
解决方案
推荐阅读
- python - 如何在 discord.py 中重新启动循环?
- asp.net-core-mvc - 模型绑定在 .Net Core 的输入参数控制器中无法正常工作
- wordpress - 使用 notepad++ 自定义分隔符将 .txt 转换为正确的 .csv
- javascript - 我是否必须将我创建并想要导入的任何脚本/模块放置在 node_modules 文件夹中?
- microsoft-graph-api - 架构扩展:“为资源 'User' 的属性 'companyName' 指定了不受支持或无效的查询过滤器子句。”
- c++ - 如何从命名空间转发声明枚举?
- php - 用于 API 响应的 Laravel 自定义包装器
- sql - 在 postgresql 中创建 N 天间隔函数
- r - 在R中的另一个列表中迭代一个列表
- r - 为 geom_line 和 geom_point 指定组