-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from kadevjo/Feature/AddedLogginGmail
added loggin with Google
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |