Archived
1
0
Fork 0

app/controllers/AuthController.php: in oauthAction() use the new implementation of OAuth.

This commit is contained in:
Henrik Hautakoski 2018-04-06 11:48:01 +02:00
parent adfeb97f1a
commit ef8e78084e

View file

@ -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);
}
}