mirror of
https://github.com/flarum/framework.git
synced 2025-01-20 03:42:44 +08:00
AbstractOAuth2Controller: Store provider and token in class properties
This way, they are available for subclasses to access them in one of the template methods. Refs #673.
This commit is contained in:
parent
588dd7b213
commit
4c03f13fef
|
@ -23,6 +23,18 @@ abstract class AbstractOAuth2Controller implements ControllerInterface
|
|||
*/
|
||||
protected $authResponse;
|
||||
|
||||
/**
|
||||
* @var \League\OAuth2\Client\Provider\AbstractProvider
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
/**
|
||||
* The access token, once obtained.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
* @param AuthenticationResponseFactory $authResponse
|
||||
*/
|
||||
|
@ -39,7 +51,7 @@ abstract class AbstractOAuth2Controller implements ControllerInterface
|
|||
{
|
||||
$redirectUri = (string) $request->getAttribute('originalUri', $request->getUri())->withQuery('');
|
||||
|
||||
$provider = $this->getProvider($redirectUri);
|
||||
$this->provider = $this->getProvider($redirectUri);
|
||||
|
||||
$session = $request->getAttribute('session');
|
||||
|
||||
|
@ -48,8 +60,8 @@ abstract class AbstractOAuth2Controller implements ControllerInterface
|
|||
$state = array_get($queryParams, 'state');
|
||||
|
||||
if (! $code) {
|
||||
$authUrl = $provider->getAuthorizationUrl($this->getAuthorizationUrlOptions());
|
||||
$session->set('oauth2state', $provider->getState());
|
||||
$authUrl = $this->provider->getAuthorizationUrl($this->getAuthorizationUrlOptions());
|
||||
$session->set('oauth2state', $this->provider->getState());
|
||||
|
||||
return new RedirectResponse($authUrl.'&display=popup');
|
||||
} elseif (! $state || $state !== $session->get('oauth2state')) {
|
||||
|
@ -58,9 +70,9 @@ abstract class AbstractOAuth2Controller implements ControllerInterface
|
|||
exit;
|
||||
}
|
||||
|
||||
$token = $provider->getAccessToken('authorization_code', compact('code'));
|
||||
$this->token = $this->provider->getAccessToken('authorization_code', compact('code'));
|
||||
|
||||
$owner = $provider->getResourceOwner($token);
|
||||
$owner = $this->provider->getResourceOwner($this->token);
|
||||
|
||||
$identification = $this->getIdentification($owner);
|
||||
$suggestions = $this->getSuggestions($owner);
|
||||
|
|
Loading…
Reference in New Issue
Block a user