datatable.directory codebase
https://datatable.directory/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.2 KiB
57 lines
1.2 KiB
<?php namespace SocialNorm;
|
|
|
|
use SocialNorm\Exceptions\InvalidAuthorizationCodeException;
|
|
|
|
class SocialNorm
|
|
{
|
|
protected $providers;
|
|
protected $session;
|
|
protected $request;
|
|
protected $stateGenerator;
|
|
|
|
public function __construct(
|
|
ProviderRegistry $providers,
|
|
Session $session,
|
|
Request $request,
|
|
StateGenerator $stateGenerator
|
|
)
|
|
{
|
|
$this->providers = $providers;
|
|
$this->session = $session;
|
|
$this->request = $request;
|
|
$this->stateGenerator = $stateGenerator;
|
|
}
|
|
|
|
public function registerProvider($alias, Provider $provider)
|
|
{
|
|
$this->providers->registerProvider($alias, $provider);
|
|
}
|
|
|
|
public function authorize($providerAlias)
|
|
{
|
|
$state = $this->stateGenerator->generate();
|
|
|
|
\Session::put('oauth.state', $state);
|
|
\Session::save();
|
|
|
|
return $this->getProvider($providerAlias)->authorizeUrl($state);
|
|
}
|
|
|
|
public function getUser($providerAlias)
|
|
{
|
|
$this->verifyState();
|
|
return $this->getProvider($providerAlias)->getUser();
|
|
}
|
|
|
|
protected function getProvider($providerAlias)
|
|
{
|
|
return $this->providers->getProvider($providerAlias);
|
|
}
|
|
|
|
protected function verifyState()
|
|
{
|
|
if (\Session::get('oauth.state') !== $this->request->state()) {
|
|
throw new InvalidAuthorizationCodeException("State failed to verify");
|
|
}
|
|
}
|
|
}
|
|
|