some fixes and removed the laravel ad-esque home view

This commit is contained in:
2018-07-09 00:17:07 +02:00
parent 6e2040249b
commit fd296e2d8f
5 changed files with 71 additions and 143 deletions
@@ -1,56 +1,58 @@
<?php namespace SocialNorm;
use SocialNorm\Exceptions\InvalidAuthorizationCodeException;
use SocialNorm\State\StateManager;
class SocialNorm
{
protected $providers;
protected $session;
protected $request;
protected $stateGenerator;
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 __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 registerProvider($alias, Provider $provider)
{
$this->providers->registerProvider($alias, $provider);
}
public function authorize($providerAlias)
{
$state = $this->stateGenerator->generate();
$this->session->put('oauth.state', $state);
return $this->getProvider($providerAlias)->authorizeUrl($state);
}
public function authorize($providerAlias)
{
$state = $this->stateGenerator->generate();
public function getUser($providerAlias)
{
$this->verifyState();
return $this->getProvider($providerAlias)->getUser();
}
// this is for some reason needed, plain put doesn't work across the redirect
\Session::put('oauth.state', $state);
\Session::save();
protected function getProvider($providerAlias)
{
return $this->providers->getProvider($providerAlias);
}
return $this->getProvider($providerAlias)->authorizeUrl($state);
}
protected function verifyState()
{
// FIXME this is broken, can't find why
// if ($this->session->get('oauth.state') !== $this->request->state()) {
// throw new InvalidAuthorizationCodeException;
// }
}
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;
}
}
}