首页 > 解决方案 > 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 我会提供该项目的链接,但我不确定它是否会被视为垃圾邮件。

标签: phpgoogle-oauth

解决方案


推荐阅读