|
|
|
<?php namespace AdamWathan\EloquentOAuth;
|
|
|
|
|
|
|
|
use SocialNorm\Provider;
|
|
|
|
use SocialNorm\SocialNorm;
|
|
|
|
|
|
|
|
class OAuthManager
|
|
|
|
{
|
|
|
|
/** @var \Illuminate\Routing\Redirector */
|
|
|
|
protected $redirect;
|
|
|
|
|
|
|
|
/** @var Authenticator */
|
|
|
|
protected $authenticator;
|
|
|
|
|
|
|
|
/** @var SocialNorm */
|
|
|
|
protected $socialnorm;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
\Illuminate\Routing\Redirector $redirect,
|
|
|
|
Authenticator $authenticator,
|
|
|
|
SocialNorm $socialnorm)
|
|
|
|
{
|
|
|
|
$this->redirect = $redirect;
|
|
|
|
$this->authenticator = $authenticator;
|
|
|
|
$this->socialnorm = $socialnorm;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function authorize(string $providerAlias)
|
|
|
|
{
|
|
|
|
return $this->redirect->to($this->socialnorm->authorize($providerAlias));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $providerAlias
|
|
|
|
* @param \Closure|null $callback
|
|
|
|
*/
|
|
|
|
public function login(string $providerAlias, $callback = null)
|
|
|
|
{
|
|
|
|
$details = $this->socialnorm->getUser($providerAlias);
|
|
|
|
return $this->authenticator->login($providerAlias, $details, $callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function registerProvider(string $alias, Provider $provider)
|
|
|
|
{
|
|
|
|
$this->socialnorm->registerProvider($alias, $provider);
|
|
|
|
}
|
|
|
|
}
|