app/controllers/AuthController.php: in oauthAction() use the new implementation of OAuth.
This commit is contained in:
parent
adfeb97f1a
commit
ef8e78084e
1 changed files with 23 additions and 8 deletions
|
|
@ -40,16 +40,31 @@ class AuthController extends ControllerBase
|
|||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
public function oauthAction()
|
||||
public function oauthAction($provider_name)
|
||||
{
|
||||
$response = $this->oauth->perform();
|
||||
$client = $this->getDI()->get('oauth', [ $provider_name ]);
|
||||
|
||||
if (is_array($response)) {
|
||||
$this->auth->loginOauth($response['auth']);
|
||||
$this->response->redirect('/');
|
||||
} else {
|
||||
$this->flash->message('error', 'Failed to authenticate.');
|
||||
$this->response->redirect('/login');
|
||||
$code = $this->request->get('code');
|
||||
$state = $this->request->get('state');
|
||||
|
||||
// Have code. Authenticate and fetch data.
|
||||
if (strlen($code) > 0) {
|
||||
|
||||
try {
|
||||
// NOTE: Should pass $state here also.
|
||||
$data = $client->authenticate($code);
|
||||
|
||||
$this->auth->loginOauth($data);
|
||||
$this->response->redirect('/');
|
||||
} catch(\Exception $e) {
|
||||
$this->flash->message('error', 'Failed to authenticate.');
|
||||
$this->response->redirect('/login');
|
||||
}
|
||||
}
|
||||
// No code
|
||||
else {
|
||||
// redirect to provider and acquire code.
|
||||
$this->response->redirect($client->getAuthorizationUrl(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue