mirror of
https://github.com/flarum/framework.git
synced 2025-02-02 09:05:38 +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
f13956d94b
commit
68759bbc4a
|
@ -23,6 +23,18 @@ abstract class AbstractOAuth2Controller implements ControllerInterface
|
||||||
*/
|
*/
|
||||||
protected $authResponse;
|
protected $authResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \League\OAuth2\Client\Provider\AbstractProvider
|
||||||
|
*/
|
||||||
|
protected $provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The access token, once obtained.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $token;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param AuthenticationResponseFactory $authResponse
|
* @param AuthenticationResponseFactory $authResponse
|
||||||
*/
|
*/
|
||||||
|
@ -39,7 +51,7 @@ abstract class AbstractOAuth2Controller implements ControllerInterface
|
||||||
{
|
{
|
||||||
$redirectUri = (string) $request->getAttribute('originalUri', $request->getUri())->withQuery('');
|
$redirectUri = (string) $request->getAttribute('originalUri', $request->getUri())->withQuery('');
|
||||||
|
|
||||||
$provider = $this->getProvider($redirectUri);
|
$this->provider = $this->getProvider($redirectUri);
|
||||||
|
|
||||||
$session = $request->getAttribute('session');
|
$session = $request->getAttribute('session');
|
||||||
|
|
||||||
|
@ -48,8 +60,8 @@ abstract class AbstractOAuth2Controller implements ControllerInterface
|
||||||
$state = array_get($queryParams, 'state');
|
$state = array_get($queryParams, 'state');
|
||||||
|
|
||||||
if (! $code) {
|
if (! $code) {
|
||||||
$authUrl = $provider->getAuthorizationUrl($this->getAuthorizationUrlOptions());
|
$authUrl = $this->provider->getAuthorizationUrl($this->getAuthorizationUrlOptions());
|
||||||
$session->set('oauth2state', $provider->getState());
|
$session->set('oauth2state', $this->provider->getState());
|
||||||
|
|
||||||
return new RedirectResponse($authUrl.'&display=popup');
|
return new RedirectResponse($authUrl.'&display=popup');
|
||||||
} elseif (! $state || $state !== $session->get('oauth2state')) {
|
} elseif (! $state || $state !== $session->get('oauth2state')) {
|
||||||
|
@ -58,9 +70,9 @@ abstract class AbstractOAuth2Controller implements ControllerInterface
|
||||||
exit;
|
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);
|
$identification = $this->getIdentification($owner);
|
||||||
$suggestions = $this->getSuggestions($owner);
|
$suggestions = $this->getSuggestions($owner);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user