added socialite and some hacks via vendor sideload to add social login

This commit is contained in:
2018-07-08 23:59:32 +02:00
parent d1fa087121
commit 6e2040249b
123 changed files with 4356 additions and 6 deletions
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class DataTable extends Model
{
//
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\Pivot;
class DiscussionFollow extends Pivot
{
//
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class TableComment extends Model
{
//
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\Pivot;
class TableFavourite extends Pivot
{
//
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class TableRevision extends Model
{
//
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\Pivot;
class UserFollow extends Pivot
{
//
}
+76
View File
@@ -0,0 +1,76 @@
<?php namespace AdamWathan\EloquentOAuth;
class Authenticator
{
protected $auth;
protected $users;
protected $identities;
public function __construct($auth, $users, $identities)
{
$this->auth = $auth;
$this->users = $users;
$this->identities = $identities;
}
public function login($providerAlias, $userDetails, $callback = null, $remember = false)
{
$user = $this->getUser($providerAlias, $userDetails);
$user = $this->runCallback($callback, $user, $userDetails);
$this->updateUser($user, $providerAlias, $userDetails);
$this->auth->login($user, $remember);
}
protected function getUser($providerAlias, $details)
{
if ($this->identities->userExists($providerAlias, $details)) {
return $this->getExistingUser($providerAlias, $details);
}
return $this->users->create();
}
protected function runCallback($callback, $user, $userDetails)
{
$callback = $callback ?: function () {};
$callbackUser = $callback($user, $userDetails);
return $callbackUser ?: $user;
}
protected function updateUser($user, $providerAlias, $details)
{
$this->users->store($user);
$this->storeProviderIdentity($user, $providerAlias, $details);
}
protected function getExistingUser($providerAlias, $details)
{
$identity = $this->identities->getByProvider($providerAlias, $details);
return $this->users->findByIdentity($identity);
}
protected function storeProviderIdentity($user, $providerAlias, $details)
{
if ($this->identities->userExists($providerAlias, $details)) {
$this->updateProviderIdentity($providerAlias, $details);
} else {
$this->addProviderIdentity($user, $providerAlias, $details);
}
}
protected function updateProviderIdentity($providerAlias, $details)
{
$identity = $this->identities->getByProvider($providerAlias, $details);
$identity->access_token = $details->access_token;
$this->identities->store($identity);
}
protected function addProviderIdentity($user, $providerAlias, $details)
{
$identity = new OAuthIdentity;
$identity->user_id = $user->getKey();
$identity->provider = $providerAlias;
$identity->provider_user_id = $details->id;
$identity->access_token = $details->access_token;
$this->identities->store($identity);
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php namespace AdamWathan\EloquentOAuth;
class EloquentIdentityStore implements IdentityStore
{
public function getByProvider($provider, $providerUser)
{
return OAuthIdentity::where('provider', $provider)
->where('provider_user_id', $providerUser->id)
->first();
}
public function flush($user, $provider)
{
OAuthIdentity::where('user_id', $user->getKey())
->where('provider', $provider)
->delete();
}
public function store($identity)
{
$identity->save();
}
public function userExists($provider, $providerUser)
{
return (bool) $this->getByProvider($provider, $providerUser);
}
}
+11
View File
@@ -0,0 +1,11 @@
<?php namespace AdamWathan\EloquentOAuth\Facades;
use Illuminate\Support\Facades\Facade;
class OAuth extends Facade
{
protected static function getFacadeAccessor()
{
return 'adamwathan.oauth';
}
}
+9
View File
@@ -0,0 +1,9 @@
<?php namespace AdamWathan\EloquentOAuth;
interface IdentityStore
{
public function getByProvider($provider, $providerUser);
public function flush($user, $provider);
public function store($identity);
public function userExists($provider, $providerUser);
}
+26
View File
@@ -0,0 +1,26 @@
<?php namespace AdamWathan\EloquentOAuth;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Config;
/**
* @property $id
* @property $user_id
* @property $provider
* @property $provider_user_id
* @property $access_token
*/
class OAuthIdentity extends Eloquent
{
protected static $configuredTable = 'oauth_identities';
public static function configureTable($table)
{
static::$configuredTable = $table;
}
public function getTable()
{
return static::$configuredTable;
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php namespace AdamWathan\EloquentOAuth;
class OAuthManager
{
protected $redirect;
protected $authenticator;
protected $socialnorm;
public function __construct($redirect, $authenticator, $socialnorm)
{
$this->redirect = $redirect;
$this->authenticator = $authenticator;
$this->socialnorm = $socialnorm;
}
public function authorize($providerAlias)
{
return $this->redirect->to($this->socialnorm->authorize($providerAlias));
}
public function login($providerAlias, $callback = null)
{
$details = $this->socialnorm->getUser($providerAlias);
return $this->authenticator->login($providerAlias, $details, $callback, $remember = false);
}
public function loginForever($providerAlias, $callback = null)
{
$details = $this->socialnorm->getUser($providerAlias);
return $this->authenticator->login($providerAlias, $details, $callback, $remember = true);
}
public function registerProvider($alias, $provider)
{
$this->socialnorm->registerProvider($alias, $provider);
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php namespace AdamWathan\EloquentOAuth;
use SocialNorm\Session as SocialNormSession;
class Session implements SocialNormSession
{
private $store;
public function __construct($store)
{
$this->store = $store;
}
public function get($key)
{
return $this->store->get($key);
}
public function put($key, $value)
{
return $this->store->put($key, $value);
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php namespace AdamWathan\EloquentOAuth;
class UserStore
{
protected $model;
public function __construct($model)
{
$this->model = $model;
}
public function create()
{
$user = new $this->model;
return $user;
}
public function store($user)
{
return $user->save();
}
public function findByIdentity($identity)
{
return $identity->belongsTo($this->model, 'user_id')->firstOrFail();
}
}