3 namespace BookStack\Http\Controllers\Auth;
5 use BookStack\Auth\Access\Oidc\OidcService;
6 use BookStack\Http\Controllers\Controller;
7 use Illuminate\Http\Request;
9 class OidcController extends Controller
11 protected $oidcService;
14 * OpenIdController constructor.
16 public function __construct(OidcService $oidcService)
18 $this->oidcService = $oidcService;
19 $this->middleware('guard:oidc');
23 * Start the authorization login flow via OIDC.
25 public function login()
27 $loginDetails = $this->oidcService->login();
28 session()->flash('oidc_state', $loginDetails['state']);
30 return redirect($loginDetails['url']);
34 * Authorization flow redirect callback.
35 * Processes authorization response from the OIDC Authorization Server.
37 public function callback(Request $request)
39 $storedState = session()->pull('oidc_state');
40 $responseState = $request->query('state');
42 if ($storedState !== $responseState) {
43 $this->showErrorNotification(trans('errors.oidc_fail_authed', ['system' => config('oidc.name')]));
45 return redirect('/login');
48 $this->oidcService->processAuthorizeResponse($request->query('code'));
50 return redirect()->intended();