3 namespace BookStack\Http\Controllers\Auth;
5 use BookStack\Auth\Access\Oidc\OidcService;
6 use BookStack\Auth\Access\Oidc\OidcException;
7 use BookStack\Http\Controllers\Controller;
8 use Illuminate\Http\Request;
10 class OidcController extends Controller
12 protected OidcService $oidcService;
15 * OpenIdController constructor.
17 public function __construct(OidcService $oidcService)
19 $this->oidcService = $oidcService;
20 $this->middleware('guard:oidc');
24 * Start the authorization login flow via OIDC.
26 public function login()
29 $loginDetails = $this->oidcService->login();
30 } catch (OidcException $exception) {
31 $this->showErrorNotification($exception->getMessage());
32 return redirect('/login');
35 session()->flash('oidc_state', $loginDetails['state']);
37 return redirect($loginDetails['url']);
41 * Authorization flow redirect callback.
42 * Processes authorization response from the OIDC Authorization Server.
44 public function callback(Request $request)
46 $storedState = session()->pull('oidc_state');
47 $responseState = $request->query('state');
49 if ($storedState !== $responseState) {
50 $this->showErrorNotification(trans('errors.oidc_fail_authed', ['system' => config('oidc.name')]));
52 return redirect('/login');
56 $this->oidcService->processAuthorizeResponse($request->query('code'));
57 } catch (OidcException $oidcException) {
58 $this->showErrorNotification($oidcException->getMessage());
59 return redirect('/login');
62 return redirect()->intended();