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; $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)) { $code = $this->request->get('code');
$this->auth->loginOauth($response['auth']); $state = $this->request->get('state');
$this->response->redirect('/');
} else { // Have code. Authenticate and fetch data.
$this->flash->message('error', 'Failed to authenticate.'); if (strlen($code) > 0) {
$this->response->redirect('/login');
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);
} }
} }