mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 22:54:25 +01:00
f8f0a23a10
* bug fixes for OAuth * Add support for Multi-DB Lookup
57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php namespace App\Ninja\OAuth;
|
|
|
|
use App\Models\LookupUser;
|
|
use App\Models\User;
|
|
|
|
class OAuth {
|
|
|
|
const SOCIAL_GOOGLE = 1;
|
|
const SOCIAL_FACEBOOK = 2;
|
|
const SOCIAL_GITHUB = 3;
|
|
const SOCIAL_LINKEDIN = 4;
|
|
|
|
private $providerInstance;
|
|
private $providerId;
|
|
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
public function getProvider($provider)
|
|
{
|
|
switch ($provider)
|
|
{
|
|
case 'google';
|
|
$this->providerInstance = new Providers\Google();
|
|
$this->providerId = self::SOCIAL_GOOGLE;
|
|
return $this;
|
|
|
|
default:
|
|
return null;
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function getTokenResponse($token)
|
|
{
|
|
$user = null;
|
|
|
|
$payload = $this->providerInstance->getTokenResponse($token);
|
|
$oauthUserId = $this->providerInstance->harvestSubField($payload);
|
|
|
|
LookupUser::setServerByField('oauth_user_key', $this->providerId . '-' . $oauthUserId);
|
|
|
|
if($this->providerInstance)
|
|
$user = User::where('oauth_user_id', $oauthUserId)->where('oauth_provider_id', $this->providerId)->first();
|
|
|
|
|
|
if ($user)
|
|
return $user;
|
|
else
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
?>
|