-
Notifications
You must be signed in to change notification settings - Fork 0
Map LoginController failures to specific HTTP errors #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
075e3dd
a367f8c
a341a30
65ab332
c3385ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ | |
| use Symfony\Component\HttpFoundation\RedirectResponse; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpFoundation\Session\SessionInterface; | ||
| use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
| use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; | ||
|
|
||
| /** | ||
| * Login Controller class. | ||
|
|
@@ -23,11 +25,18 @@ public function __construct( | |
| /** | ||
| * Login method redirecting to authorizer. | ||
| * | ||
| * @throws ItkOpenIdConnectException|InvalidProviderException | ||
| * @throws NotFoundHttpException Provider key not configured (404) | ||
| * @throws ServiceUnavailableHttpException IdP unreachable, returned a non-200, served malformed JSON, or local cache failed (503) | ||
| * @throws ItkOpenIdConnectException Other provider-init failures (e.g. BadUrlException for a misconfigured metadata_url) — server-side configuration bugs that intentionally bubble as 500 | ||
| * @throws \InvalidArgumentException Declared by league\AbstractProvider::getAuthorizationUrl for missing scope/state. Unreachable in this flow (state always provided, getDefaultScopes() implemented in upstream OpenIdConfigurationProvider). Bubbles as 500 if it ever fires — programmer error. | ||
| */ | ||
| public function login(Request $request, SessionInterface $session, string $providerKey): RedirectResponse | ||
| { | ||
| $provider = $this->providerManager->getProvider($providerKey); | ||
| try { | ||
| $provider = $this->providerManager->getProvider($providerKey); | ||
| } catch (InvalidProviderException $e) { | ||
| throw new NotFoundHttpException(sprintf('Unknown OIDC provider "%s"', $providerKey), $e); | ||
| } | ||
|
|
||
| $nonce = $provider->generateNonce(); | ||
| $state = $provider->generateState(); | ||
|
|
@@ -37,12 +46,19 @@ public function login(Request $request, SessionInterface $session, string $provi | |
| $session->set('oauth2state', $state); | ||
| $session->set('oauth2nonce', $nonce); | ||
|
|
||
| $authUrl = $provider->getAuthorizationUrl([ | ||
| 'state' => $state, | ||
| 'nonce' => $nonce, | ||
| 'response_type' => 'code', | ||
| 'scope' => 'openid email profile', | ||
| ]); | ||
| try { | ||
| $authUrl = $provider->getAuthorizationUrl([ | ||
| 'state' => $state, | ||
| 'nonce' => $nonce, | ||
| 'response_type' => 'code', | ||
| 'scope' => 'openid email profile', | ||
| ]); | ||
| } catch (ItkOpenIdConnectException $e) { | ||
| // Building the authorization URL fetches the IdP's discovery | ||
| // document. Surface upstream/transport/cache failures as 503 with | ||
| // the cause chained, rather than an unhandled 500. | ||
| throw new ServiceUnavailableHttpException(null, sprintf('Cannot reach OIDC provider "%s"', $providerKey), $e); | ||
| } | ||
|
Comment on lines
+49
to
+61
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to https://github.com/itk-dev/openid-connect/blob/develop/src/Security/OpenIdConfigurationProvider.php#L119 and https://github.com/thephpleague/oauth2-client/blob/master/src/Provider/AbstractProvider.php#L483 this throws either a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| return new RedirectResponse($authUrl); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/itk-dev/openid-connect-bundle/blob/feature/login-controller-http-errors/src/Security/OpenIdConfigurationProviderManager.php#L52-L58 seems to indicate that this throws more than just
InvalidProviderException.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@throwsupdated.