Switch Google login to native client

This commit is contained in:
2022-04-04 01:03:39 -04:00
parent 769e1bc7b1
commit 59f0e75842
5 changed files with 151 additions and 58 deletions
+5 -1
View File
@@ -23,12 +23,16 @@ class Home extends WRB_Controller {
// Load Hybridauth's helper
$this->load->helper('hybridauth');
/*
// Instantiate Hybridauth's classes
$hybrid = new Hybridauth(get_hybridauth_config());
// Get login links
$login_links = get_hybridauth_links($hybrid, $this->router);
*/
$login_links = array(
'Google' => get_google_login_link()
);
// Pass login links to html template
$data['login_links'] = $login_links;
+83 -53
View File
@@ -162,12 +162,16 @@ class Login extends WRB_Controller {
// Load Hybridauth's helper
$this->load->helper('hybridauth');
/*
// Instantiate Hybridauth's classes
$hybrid = new Hybridauth(get_hybridauth_config());
// Get login links
$login_links = get_hybridauth_links($hybrid, $this->router);
*/
$login_links = array(
'Google' => get_google_login_link()
);
// Pass login links to html template
$data['login_links'] = $login_links;
@@ -216,6 +220,82 @@ class Login extends WRB_Controller {
//Processes social login
function auth($provider = NULL)
{
// Load Hybridauth's helper
$this->load->helper('hybridauth');
$code = $this->input->get('code');
if ($code!='') {
$client = get_google_client();
$token = $client->fetchAccessTokenWithAuthCode($code);
$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;
var_dump($google_account_info);
exit();
if ($email != '') {
/*
$user = array(
'id' => '',
'name' => '',
'email' => ''
);
list($proceed, $data) = $this->checkUserExists($user, $data);
// TODO
if ($proceed) {
$name = (string) $user["name"];
if (trim($name) == "")
$name = strtok($user["email"], "@");
$data['fb_id'] = $user["id"];
$data['firstname'] = strtok($name, " ");
$data['lastname'] = strtok(" ");
$data['email'] = $user["email"];
$data['sessionid'] = rand(10000, 99999) . "A" . rand(10000, 99999);
$data['action'] = WRENCHBOARD_FACEBOOK_LOGIN;
$this->load->model('backend_model');
$out = array();
$res = $this->backend_model->wrenchboard_api($data, $out);
if ($res == PHP_LOGIN_OK) {
$this->load->model('account_model');
$ret = $this->account_model->username_data($out);
if ($res !== false) {
$data["login_message"] = "Welcome...";
// yes person has an account
$_SESSION['session_id'] = $out["session"];
$_SESSION['username'] = $ret->username;
$_SESSION['name'] = $ret->username;
$_SESSION['firstname'] = $ret->firstname;
$_SESSION['lastname'] = $ret->lastname;
$_SESSION['email'] = $ret->email;
$_SESSION['member_id'] = $ret->id;
$_SESSION['log_count'] = 0;
$_SESSION['mesaage_count'] = 0;
$this->findOffers($_SESSION['email']);
$_SESSION['message_snapshot'] = $this->myMessagesSnapshot();
$this->logUser('Account login');
$this->refreshAccountDetail($_SESSION['member_id']);
$this->getSessionArray();
$this->excudedEmails();
redirect('dash');
}
}
}
// */
}
}
}
//Processes social login
function authh($provider = NULL)
{
// Load Hybridauth's helper
$this->load->helper('hybridauth');
@@ -239,6 +319,8 @@ class Login extends WRB_Controller {
if ($provider)
{
$service = $hybrid->authenticate($provider);
var_dump($service);
exit();
if ($service->isConnected())
{
//Get user profile
@@ -260,58 +342,6 @@ class Login extends WRB_Controller {
echo 'Name: ' . $profile->displayName;
print_r($profile);
exit();
/*
$user = array(
'id' => '',
'name' => '',
'email' => ''
);
list($proceed, $data) = $this->checkUserExists($user, $data);
// TODO
if ($proceed) {
$name = (string) $user["name"];
if (trim($name) == "")
$name = strtok($user["email"], "@");
$data['fb_id'] = $user["id"];
$data['firstname'] = strtok($name, " ");
$data['lastname'] = strtok(" ");
$data['email'] = $user["email"];
$data['sessionid'] = rand(10000, 99999) . "A" . rand(10000, 99999);
$data['action'] = WRENCHBOARD_FACEBOOK_LOGIN;
$this->load->model('backend_model');
$out = array();
$res = $this->backend_model->wrenchboard_api($data, $out);
if ($res == PHP_LOGIN_OK) {
$this->load->model('account_model');
$ret = $this->account_model->username_data($out);
if ($res !== false) {
$data["login_message"] = "Welcome...";
// yes person has an account
$_SESSION['session_id'] = $out["session"];
$_SESSION['username'] = $ret->username;
$_SESSION['name'] = $ret->username;
$_SESSION['firstname'] = $ret->firstname;
$_SESSION['lastname'] = $ret->lastname;
$_SESSION['email'] = $ret->email;
$_SESSION['member_id'] = $ret->id;
$_SESSION['log_count'] = 0;
$_SESSION['mesaage_count'] = 0;
$this->findOffers($_SESSION['email']);
$_SESSION['message_snapshot'] = $this->myMessagesSnapshot();
$this->logUser('Account login');
$this->refreshAccountDetail($_SESSION['member_id']);
$this->getSessionArray();
$this->excudedEmails();
redirect('dash');
}
}
}
// */
}
else
{
+5 -1
View File
@@ -17,12 +17,16 @@ class Site extends WRB_Controller {
// Load Hybridauth's helper
$this->load->helper('hybridauth');
/*
// Instantiate Hybridauth's classes
$hybrid = new Hybridauth(get_hybridauth_config());
// Get login links
$login_links = get_hybridauth_links($hybrid, $this->router);
*/
$login_links = array(
'Google' => get_google_login_link()
);
// Pass login links to html template
$data['login_links'] = $login_links;
+55 -1
View File
@@ -1,5 +1,60 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
POST /oauth2/v4/token HTTP/1.1
Host: www.googleapis.com
Content-length: 233
content-type: application/x-www-form-urlencoded
user-agent: google-oauth-playground
code=4%2FKxoYTS-jeq5-d6Lv7YvSz9ZrK0pJ_5lZsMExzNC1M0o
&redirect_uri=https%3A%2F%2Foameye.work.wrenchboard.com%2Flogin%2Fauth%2F
&client_id=817021856543-ad9nsjgdpsu2s2jrl63j3ihrv7lbf6ma.apps.googleusercontent.com
&client_secret=aozK_2G8UjaCmLgPPkv9abIm
&scope=
&grant_type=authorization_code
https://oameye.work.wrenchboard.com/login/auth/
?state=HA-R5UG9ZADN2JL8MKPCV736QSIHTEXW4OF01YB
&code=4/0AX4XfWjGtsNysrdFaHZLp6rIOKzZjMj4zmJTQrqu0NOBdEDEuYn9LoBzJoxDFgrw43BqGA
&scope=email+profile+https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile+openid&authuser=0&
prompt=consent
curl -X POST -d 'code=4/0AX4XfWjGtsNysrdFaHZLp6rIOKzZjMj4zmJTQrqu0NOBdEDEuYn9LoBzJoxDFgrw43BqGA&redirect_uri=https%3A%2F%2Foameye.work.wrenchboard.com%2Flogin%2Fauth%2F&client_id=817021856543-ad9nsjgdpsu2s2jrl63j3ihrv7lbf6ma.apps.googleusercontent.com&client_secret=aozK_2G8UjaCmLgPPkv9abIm&scope=&grant_type=authorization_code' https://www.googleapis.com/oauth2/v4/token
*/
if ( ! function_exists('get_google_client'))
{
// Configure Google Client
function get_google_client()
{
// init configuration
$clientID = '817021856543-ad9nsjgdpsu2s2jrl63j3ihrv7lbf6ma.apps.googleusercontent.com';
$clientSecret = 'aozK_2G8UjaCmLgPPkv9abIm';
$redirectUri = site_url('login/auth/');
// 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");
return $client;
}
}
if ( ! function_exists('get_google_login_link'))
{
// Get Google login link
function get_google_login_link()
{
$client = get_google_client();
return $client->createAuthUrl();
}
}
if ( ! function_exists('get_hybridauth_config'))
{
//Hybridauth configuration
@@ -17,7 +72,6 @@ if ( ! function_exists('get_hybridauth_config'))
'secret' => 'aozK_2G8UjaCmLgPPkv9abIm'
) ,
'scope' => 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile',
'redirect_uri' => site_url('login/auth/') . '?hauth.done=google'
) ,
'Facebook' => array(
+3 -2
View File
@@ -13,9 +13,10 @@
"require": {
"php": ">=5.3.7",
"facebook/php-sdk-v4" : "~5.0",
"firebase/php-jwt": "^6.0",
"firebase/php-jwt": "^5.5.1",
"phpseclib/phpseclib": "^3.0",
"hybridauth/hybridauth" : "~3.7.1"
"hybridauth/hybridauth" : "~3.7.1",
"google/apiclient":"^2.12.1"
},
"suggest": {
"paragonie/random_compat": "Provides better randomness in PHP 5.x"