Skip to content

Commit

Permalink
Merge pull request #3 from kadevjo/Feature/AddedLogginGmail
Browse files Browse the repository at this point in the history
added loggin with Google
  • Loading branch information
dev-qualitara authored Nov 7, 2019
2 parents b20c813 + cb5db2b commit 6bc6c11
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Fibonacci.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
use Kadevjo\Fibonacci\Helpers\FacebookAccount;
use Kadevjo\Fibonacci\Helpers\OutlookAccount;
use Kadevjo\Fibonacci\Helpers\TwitterAccount;
use Kadevjo\Fibonacci\Helpers\GoogleAccount;

class Fibonacci
{
const FACEBOOK = "facebook";
const TWITTER = "twitter";
const OUTLOOK = "outlook";
const GOOGLE = "google";

public function webRoutes()
{
Expand All @@ -38,6 +40,9 @@ public static function authenticateSocial($provider, $socialID, $data)
case self::OUTLOOK:
$result = OutlookAccount::Auth($socialID, $data);
break;
case self::GOOGLE:
$result = GoogleAccount::Auth($socialID, $data);
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function up()
$table->string('avatar')->nullable();
$table->string('first_name');
$table->string('last_name');
$table->string('name');
$table->longText('channels');
$table->string('password')->nullable();
$table->string('remember_token')->nullable();
Expand Down
45 changes: 45 additions & 0 deletions src/helpers/GoogleAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Kadevjo\Fibonacci\Helpers;

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Subscriber\Oauth\Oauth1;
use GuzzleHttp\Psr7;
use Kadevjo\Fibonacci\Exceptions\ConfigException;
use Illuminate\Support\Arr;

class GoogleAccount
{
protected $email;
protected $first_name;
protected $last_name;
protected $picture;
public $account;

public static function Auth($userId, $token)
{
if( !$token ) throw new ConfigException("An error ocurred");


$client = new Client();
$res = $client->request('GET', 'https://www.googleapis.com/oauth2/v3/userinfo?', [
'query' => [
'prettyPrint' => 'false',
],
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$token,
],]);


$response = json_decode($res->getBody(), true);
$email = Arr::get($response, 'email');
$first_name = Arr::get($response, 'name');
$last_name = Arr::get($response, 'name');
$picture =Arr::get($response, 'picture');
$backend = json_decode(json_encode(array('email'=>$email, 'picture'=>$picture, 'first_name'=>$first_name,'last_name'=>null)), FALSE);
return $backend;
}

}

0 comments on commit 6bc6c11

Please sign in to comment.