|
9 | 9 | use MediaWiki\OAuthClient\Client; |
10 | 10 | use MediaWiki\OAuthClient\ClientConfig; |
11 | 11 | use MediaWiki\OAuthClient\Consumer; |
12 | | -use MediaWiki\OAuthClient\Exception; |
| 12 | +use MediaWiki\OAuthClient\Exception as OAuthException; |
13 | 13 | use MediaWiki\OAuthClient\Token; |
14 | 14 | use OpenApi\Annotations as OA; |
15 | 15 | use Symfony\Component\HttpFoundation\JsonResponse; |
@@ -71,7 +71,7 @@ public function loginAction( |
71 | 71 | try { |
72 | 72 | [$next, $token] = $this->getOauthClient($request, $projectRepo, $urlGenerator, $centralAuthProject) |
73 | 73 | ->initiate(); |
74 | | - } catch (Exception $oauthException) { |
| 74 | + } catch (OAuthException $oauthException) { |
75 | 75 | $this->addFlashMessage('notice', 'error-login'); |
76 | 76 | return $this->redirectToRoute('homepage'); |
77 | 77 | } |
@@ -113,19 +113,24 @@ public function oauthCallbackAction( |
113 | 113 | return $this->redirectToRoute('homepage'); |
114 | 114 | } |
115 | 115 |
|
116 | | - $verifier = $request->get('oauth_verifier'); |
117 | | - $accessToken = $client->complete($token, $verifier); |
| 116 | + try { |
| 117 | + $verifier = $request->get('oauth_verifier'); |
| 118 | + $accessToken = $client->complete($token, $verifier); |
118 | 119 |
|
119 | | - // Store access token, and remove request token. |
120 | | - $session->set('oauth_access_token', $accessToken); |
121 | | - $session->remove('oauth_request_token'); |
| 120 | + // Store access token, and remove request token. |
| 121 | + $session->set('oauth_access_token', $accessToken); |
| 122 | + $session->remove('oauth_request_token'); |
122 | 123 |
|
123 | | - // Store user identity. |
124 | | - $ident = $client->identify($accessToken); |
125 | | - $session->set('logged_in_user', $ident); |
| 124 | + // Store user identity. |
| 125 | + $ident = $client->identify($accessToken); |
| 126 | + $session->set('logged_in_user', $ident); |
126 | 127 |
|
127 | | - // Store reference to the client. |
128 | | - $session->set('oauth_client', $this->oauthClient); |
| 128 | + // Store reference to the client. |
| 129 | + $session->set('oauth_client', $this->oauthClient); |
| 130 | + } catch (OAuthException $e) { |
| 131 | + $this->addFlashMessage('notice', 'error-login'); |
| 132 | + // Redirect below |
| 133 | + } |
129 | 134 |
|
130 | 135 | // Redirect to callback, if given. |
131 | 136 | if ($request->query->get('redirect')) { |
|
0 commit comments