namespace BookStack\Http\Controllers\Auth;
+use BookStack\Auth\Access\Oidc\OidcException;
use BookStack\Auth\Access\Oidc\OidcService;
use BookStack\Http\Controllers\Controller;
use Illuminate\Http\Request;
class OidcController extends Controller
{
-
- protected $oidcService;
+ protected OidcService $oidcService;
/**
* OpenIdController constructor.
*/
public function login()
{
- $loginDetails = $this->oidcService->login();
+ try {
+ $loginDetails = $this->oidcService->login();
+ } catch (OidcException $exception) {
+ $this->showErrorNotification($exception->getMessage());
+
+ return redirect('/login');
+ }
+
session()->flash('oidc_state', $loginDetails['state']);
return redirect($loginDetails['url']);
if ($storedState !== $responseState) {
$this->showErrorNotification(trans('errors.oidc_fail_authed', ['system' => config('oidc.name')]));
+
+ return redirect('/login');
+ }
+
+ try {
+ $this->oidcService->processAuthorizeResponse($request->query('code'));
+ } catch (OidcException $oidcException) {
+ $this->showErrorNotification($oidcException->getMessage());
+
return redirect('/login');
}
- $this->oidcService->processAuthorizeResponse($request->query('code'));
return redirect()->intended();
}
}