mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-03 22:33:38 +08:00
ce566bea2a
Fixes issue where certain errors would not show to the user due to extra navigation jumps which lost the error message in the process. This simplifies and aligns exceptions with more directly handled exception usage at the controller level. Fixes #3264
65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace BookStack\Http\Controllers\Auth;
|
|
|
|
use BookStack\Auth\Access\Oidc\OidcService;
|
|
use BookStack\Auth\Access\Oidc\OidcException;
|
|
use BookStack\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
|
|
class OidcController extends Controller
|
|
{
|
|
protected OidcService $oidcService;
|
|
|
|
/**
|
|
* OpenIdController constructor.
|
|
*/
|
|
public function __construct(OidcService $oidcService)
|
|
{
|
|
$this->oidcService = $oidcService;
|
|
$this->middleware('guard:oidc');
|
|
}
|
|
|
|
/**
|
|
* Start the authorization login flow via OIDC.
|
|
*/
|
|
public function 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']);
|
|
}
|
|
|
|
/**
|
|
* Authorization flow redirect callback.
|
|
* Processes authorization response from the OIDC Authorization Server.
|
|
*/
|
|
public function callback(Request $request)
|
|
{
|
|
$storedState = session()->pull('oidc_state');
|
|
$responseState = $request->query('state');
|
|
|
|
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');
|
|
}
|
|
|
|
return redirect()->intended();
|
|
}
|
|
}
|