186 lines
7.2 KiB
PHP
186 lines
7.2 KiB
PHP
<?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_apple_config'))
|
|
{
|
|
function get_apple_config() {
|
|
// https://arfasoftech.com/blog/How-to-Integrate-Sign-in-with-Apple-in-PHP-(5-minute-code)
|
|
return array(
|
|
/* 'client_id' => */ 'com.wrenchboard.users.client',
|
|
/* 'client_secret' => */ 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiIsImtpZCI6Ilc1V1RXQzlEVEoifQ.eyJpc3MiOiJKUjM2M0ZFWThSIiwiaWF0IjoxNjU0MDgzODQxLCJleHAiOjE2NTkyNjc4NDEsImF1ZCI6Imh0dHBzOi8vYXBwbGVpZC5hcHBsZS5jb20iLCJzdWIiOiJjb20ud3JlbmNoYm9hcmQudXNlcnMuY2xpZW50In0.TIPMwjS2MgSysqEuw3yu1nrOcrH-6omzerDhx0CadjWn2yCO8wZhQiAlhIFs7F-WPektIJ6h-2BT62yGrILiTA',
|
|
/* 'redirect_uri' => */ site_url('login/auth/apple')
|
|
);
|
|
}
|
|
}
|
|
|
|
if ( ! function_exists('get_apple_login_link'))
|
|
{
|
|
// Configure Apple CLient
|
|
function get_apple_login_link()
|
|
{
|
|
// init configuration
|
|
list($clientID, $clientSecret, $redirectUri) = get_apple_config();
|
|
|
|
$_SESSION['apple_state'] = bin2hex(random_bytes(5));
|
|
|
|
$authorize_url = 'https://appleid.apple.com/auth/authorize'.'?'.http_build_query([
|
|
'response_type' => 'code',
|
|
'response_mode' => 'form_post',
|
|
'client_id' => $clientID,
|
|
'redirect_uri' => $redirectUri,
|
|
'state' => $_SESSION['apple_state'],
|
|
'scope' => 'name email',
|
|
]);
|
|
|
|
return $authorize_url;
|
|
}
|
|
}
|
|
|
|
/*
|
|
Client ID: com.wrenchboard.users.client
|
|
Key ID: W5WTWC9DTJ
|
|
Sign In with Apple: JR363FEY8R.com.wrenchboard.users
|
|
Secret: eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiIsImtpZCI6Ilc1V1RXQzlEVEoifQ.eyJpc3MiOiJKUjM2M0ZFWThSIiwiaWF0IjoxNjU0MDgzODQxLCJleHAiOjE2NTkyNjc4NDEsImF1ZCI6Imh0dHBzOi8vYXBwbGVpZC5hcHBsZS5jb20iLCJzdWIiOiJjb20ud3JlbmNoYm9hcmQudXNlcnMuY2xpZW50In0.TIPMwjS2MgSysqEuw3yu1nrOcrH-6omzerDhx0CadjWn2yCO8wZhQiAlhIFs7F-WPektIJ6h-2BT62yGrILiTA
|
|
*/
|
|
|
|
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
|
|
function get_hybridauth_config()
|
|
{
|
|
$config = array(
|
|
|
|
'callback' => site_url('login/auth/') ,
|
|
|
|
'providers' => array(
|
|
'Google' => array(
|
|
'enabled' => true,
|
|
'keys' => array(
|
|
'id' => '817021856543-ad9nsjgdpsu2s2jrl63j3ihrv7lbf6ma.apps.googleusercontent.com',
|
|
'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',
|
|
) ,
|
|
|
|
'Facebook' => array(
|
|
'enabled' => true,
|
|
'keys' => array(
|
|
'id' => (ENVIRONMENT == 'development') ? '390204307987009' : '390204307987009',
|
|
'secret' => (ENVIRONMENT == 'development') ? '19f778e312f2ab96d147bacb612910c2' : '19f778e312f2ab96d147bacb612910c2'
|
|
) ,
|
|
'scope' => 'email, public_profile'
|
|
) ,
|
|
|
|
'Apple' => array(
|
|
"enabled" => true,
|
|
"keys" => [
|
|
"id" => "Your Apple ID",
|
|
"team_id" => "Your Apple team id",
|
|
"key_id" => "Your Apple key id",
|
|
"key_content" => "Your Apple key (content including BEGIN and END lines)",
|
|
"key_file" => "Full path to your Apple key file (alternative to key_content)"
|
|
],
|
|
"scope" => "name email",
|
|
"verifyTokenSignature" => true
|
|
)
|
|
) ,
|
|
|
|
'hybrid_debug' => array(
|
|
'debug_mode' => 'info', /* none, debug, info, error */
|
|
'debug_file' => APPPATH . '/logs/log-' . date('Y-m-d') . '.php'
|
|
)
|
|
);
|
|
|
|
return $config;
|
|
}
|
|
}
|
|
|
|
if ( ! function_exists('get_hybridauth_links'))
|
|
{
|
|
function get_hybridauth_links($hybrid, $router)
|
|
{
|
|
$login_links = array();
|
|
|
|
//Get enabled providers array
|
|
$providers = $hybrid->getProviders();
|
|
|
|
$provider_icons = array(
|
|
'Apple' => '/site3/assets/media/svg/brand-logos/apple-black.svg',
|
|
'Facebook' => '/site3/assets/media/svg/brand-logos/facebook-4.svg',
|
|
'Google' => '/site3/assets/media/svg/brand-logos/google-icon.svg'
|
|
);
|
|
|
|
//List a link to login
|
|
foreach ($providers as $provider)
|
|
{
|
|
$login_links[$provider] = "";
|
|
//$href = sprintf(base_url('%s/auth/%s/') , strtolower($router->fetch_class()) , $provider);
|
|
$href = sprintf("%s/%s/", site_url('login/auth'), $provider);
|
|
$login_links[$provider] = $href; // .= '<a href="' . $href . '" class="btn btn-flex flex-center btn-light btn-lg w-100 mb-5">';
|
|
if (array_key_exists($provider, $provider_icons)) {
|
|
// $login_links[$provider] .= '<img alt="Logo" src="' . $provider_icons[$provider] . '" class="h-20px me-3">';
|
|
}
|
|
// $login_links[$provider] .= 'Continue with ' . $provider . '</a>';
|
|
}
|
|
|
|
return $login_links;
|
|
}
|
|
}
|
|
|
|
|
|
|