| Server IP : 14.225.204.176 / Your IP : 216.73.216.252 Web Server : nginx/1.24.0 System : Linux nodejs-ybgk 6.8.0-40-generic #40-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 5 10:34:03 UTC 2024 x86_64 User : root ( 0) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/php/mmobot/app/libraries/ |
Upload File : |
<?php
require "Google/autoload.php";
class google_oauth{
private $ClientID;
private $ClientSecret;
private $client;
private $redirect_url;
private $access_token;
public function __construct($client_id = null, $client_secret = null, $redirect_url = "auth/google"){
$this->client = new Google_Client();
$this->client->setAccessType("offline");
$this->client->setApprovalPrompt("force");
$this->client->setRedirectUri(cn($redirect_url));
$this->client->setClientId($client_id);
$this->client->setClientSecret($client_secret);
$this->client->setScopes(array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'));
$this->redirect_url = $redirect_url;
}
function create_login_url(){
return $this->client->createAuthUrl();
}
function get_access_token(){
try {
if(get("code")){
$this->client->authenticate(get("code"));
$oauth2 = new Google_Service_Oauth2($this->client);
$token = $this->client->getAccessToken();
$this->access_token = $token;
return $token;
}else{
redirect(cn($this->redirect_url));
}
} catch (Exception $e) {
redirect(cn($this->redirect_url));
}
}
function get_user_info(){
try {
$oauth2 = new Google_Service_Oauth2($this->client);
$this->client->setAccessToken($this->access_token);
$userinfo = $oauth2->userinfo->get();
return $userinfo;
} catch (Exception $e) {
return false;
}
}
}