added socialite and some hacks via vendor sideload to add social login
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
<?php namespace AdamWathan\EloquentOAuthL5;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use GuzzleHttp\Client as HttpClient;
|
||||
use SocialNorm\SocialNorm;
|
||||
use SocialNorm\ProviderRegistry;
|
||||
use SocialNorm\Request;
|
||||
use SocialNorm\StateGenerator;
|
||||
use AdamWathan\EloquentOAuth\Authenticator;
|
||||
use AdamWathan\EloquentOAuth\EloquentIdentityStore;
|
||||
use AdamWathan\EloquentOAuth\IdentityStore;
|
||||
use AdamWathan\EloquentOAuth\Session;
|
||||
use AdamWathan\EloquentOAuth\OAuthIdentity;
|
||||
use AdamWathan\EloquentOAuth\OAuthManager;
|
||||
use AdamWathan\EloquentOAuth\UserStore;
|
||||
|
||||
class EloquentOAuthServiceProvider extends ServiceProvider {
|
||||
|
||||
protected $providerLookup = [
|
||||
'facebook' => 'SocialNorm\Facebook\FacebookProvider',
|
||||
'github' => 'SocialNorm\GitHub\GitHubProvider',
|
||||
'google' => 'SocialNorm\Google\GoogleProvider',
|
||||
];
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// $this->configureOAuthIdentitiesTable();
|
||||
$this->registerIdentityStore();
|
||||
$this->registerOAuthManager();
|
||||
// $this->registerCommands();
|
||||
}
|
||||
|
||||
protected function registerIdentityStore()
|
||||
{
|
||||
$this->app->singleton('AdamWathan\EloquentOAuth\IdentityStore', function ($app) {
|
||||
return new EloquentIdentityStore;
|
||||
});
|
||||
}
|
||||
|
||||
protected function registerOAuthManager()
|
||||
{
|
||||
$this->app->singleton('adamwathan.oauth', function ($app) {
|
||||
$providerRegistry = new ProviderRegistry;
|
||||
$session = new Session($app['session']);
|
||||
$request = new Request($app['request']->all());
|
||||
$stateGenerator = new StateGenerator;
|
||||
|
||||
$socialnorm = new SocialNorm($providerRegistry, $session, $request, $stateGenerator);
|
||||
$this->registerProviders($socialnorm, $request);
|
||||
|
||||
// take user model from the config file
|
||||
$users = new UserStore($app['config']['auth.providers.users.model']);
|
||||
|
||||
$authenticator = new Authenticator(
|
||||
$app['Illuminate\Contracts\Auth\Guard'],
|
||||
$users,
|
||||
$app['AdamWathan\EloquentOAuth\IdentityStore']
|
||||
);
|
||||
|
||||
$oauth = new OAuthManager($app['redirect'], $authenticator, $socialnorm);
|
||||
return $oauth;
|
||||
});
|
||||
}
|
||||
|
||||
protected function registerProviders($socialnorm, $request)
|
||||
{
|
||||
if (! $providerAliases = $this->app['config']['services.oauth_providers']) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($providerAliases as $alias => $config) {
|
||||
if (isset($this->getProviderLookup()[$alias])) {
|
||||
$providerClass = $this->getProviderLookup()[$alias];
|
||||
|
||||
if ($this->app->bound($providerClass)) {
|
||||
$provider = $this->app->make($providerClass);
|
||||
} else {
|
||||
$provider = new $providerClass($config, new HttpClient, $request);
|
||||
}
|
||||
|
||||
$socialnorm->registerProvider($alias, $provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getProviderLookup()
|
||||
{
|
||||
return $this->providerLookup;
|
||||
}
|
||||
|
||||
// protected function configureOAuthIdentitiesTable()
|
||||
// {
|
||||
// OAuthIdentity::configureTable($this->app['config']['eloquent-oauth.table']);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Registers some utility commands with artisan
|
||||
// * @return void
|
||||
// */
|
||||
// public function registerCommands()
|
||||
// {
|
||||
// $this->app->bind('command.eloquent-oauth.install', 'AdamWathan\EloquentOAuthL5\Installation\InstallCommand');
|
||||
// $this->commands('command.eloquent-oauth.install');
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return ['adamwathan.oauth'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php namespace AdamWathan\EloquentOAuthL5\Installation;
|
||||
|
||||
use Exception;
|
||||
|
||||
class FileExistsException extends Exception {}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php namespace AdamWathan\EloquentOAuthL5\Installation;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Foundation\Composer as Composer51;
|
||||
use Illuminate\Support\Composer as Composer52;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class InstallCommand extends Command
|
||||
{
|
||||
protected $filesystem;
|
||||
protected $composer;
|
||||
protected $name = 'eloquent-oauth:install';
|
||||
protected $description = 'Install package config and migrations';
|
||||
|
||||
public function __construct(Filesystem $filesystem)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->filesystem = $filesystem;
|
||||
|
||||
if (class_exists(Composer52::class)) {
|
||||
$this->composer = app(Composer52::class);
|
||||
} else {
|
||||
$this->composer = app(Composer51::class);
|
||||
}
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$this->publishConfig();
|
||||
$this->publishMigrations();
|
||||
$this->composer->dumpAutoloads();
|
||||
$this->comment('Package configuration and migrations installed!');
|
||||
} catch (FileExistsException $e) {
|
||||
$this->error('It looks like this package has already been installed. Use --force to override.');
|
||||
}
|
||||
}
|
||||
|
||||
public function publishConfig()
|
||||
{
|
||||
$this->publishFile(__DIR__ . '/../../config/eloquent-oauth.php', config_path() . '/eloquent-oauth.php');
|
||||
$this->info('Configuration published.');
|
||||
}
|
||||
|
||||
public function publishMigrations()
|
||||
{
|
||||
$name = 'create_oauth_identities_table';
|
||||
$path = $this->laravel['path.database'] . '/migrations';
|
||||
$fullPath = $this->laravel['migration.creator']->create($name, $path);
|
||||
$this->filesystem->put($fullPath, $this->filesystem->get(__DIR__ . '/../../migrations/create_oauth_identities_table.stub'));
|
||||
}
|
||||
|
||||
public function publishFile($from, $to)
|
||||
{
|
||||
if ($this->filesystem->exists($to) && !$this->option('force')) {
|
||||
throw new FileExistsException;
|
||||
}
|
||||
|
||||
$this->filesystem->copy($from, $to);
|
||||
}
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['force', null, InputOption::VALUE_NONE, 'Overwrite any existing files.'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user