-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract Authorizer and ProviderRegistrar
- Loading branch information
1 parent
f33030b
commit ff01cb4
Showing
4 changed files
with
65 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php namespace AdamWathan\EloquentOAuth; | ||
|
||
use Illuminate\Routing\Redirector as Redirect; | ||
use AdamWathan\EloquentOAuth\Providers\ProviderInterface; | ||
|
||
class Authorizer | ||
{ | ||
protected $redirect; | ||
protected $stateManager; | ||
|
||
public function __construct(Redirect $redirect, StateManager $stateManager) | ||
{ | ||
$this->redirect = $redirect; | ||
$this->stateManager = $stateManager; | ||
} | ||
|
||
public function authorize(ProviderInterface $provider) | ||
{ | ||
$state = $this->generateState(); | ||
return $this->redirect->to($provider->authorizeUrl($state)); | ||
} | ||
|
||
protected function generateState() | ||
{ | ||
return $this->stateManager->generateState(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php namespace AdamWathan\EloquentOAuth; | ||
|
||
use AdamWathan\EloquentOAuth\Providers\ProviderInterface; | ||
use AdamWathan\EloquentOAuth\Exceptions\ProviderNotRegisteredException; | ||
|
||
class ProviderRegistrar | ||
{ | ||
private $providers = array(); | ||
|
||
public function registerProvider($alias, ProviderInterface $provider) | ||
{ | ||
$this->providers[$alias] = $provider; | ||
} | ||
|
||
public function getProvider($providerAlias) | ||
{ | ||
if (! $this->hasProvider($providerAlias)) { | ||
throw new ProviderNotRegisteredException("No provider has been registered under the alias '{$providerAlias}'"); | ||
} | ||
return $this->providers[$providerAlias]; | ||
} | ||
|
||
protected function hasProvider($alias) | ||
{ | ||
return isset($this->providers[$alias]); | ||
} | ||
} |