mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-02 05:43:40 +08:00
41438adbd1
- Removed uneeded custom refresh or logout actions for OIDC. - Restructured how the services and guards are setup for external auth systems. SAML2 and OIDC now directly share a lot more logic. - Renamed any OpenId references to OIDC or OpenIdConnect - Removed non-required CSRF excemption for OIDC Not tested, Come to roadblock due to lack of PHP8 support in upstream dependancies. Certificate was deemed to be non-valid on every test attempt due to changes in PHP8.
57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace BookStack\Http\Controllers\Auth;
|
|
|
|
use BookStack\Auth\Access\OpenIdConnectService;
|
|
use BookStack\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
|
|
class OpenIdConnectController extends Controller
|
|
{
|
|
|
|
protected $oidcService;
|
|
|
|
/**
|
|
* OpenIdController constructor.
|
|
*/
|
|
public function __construct(OpenIdConnectService $oidcService)
|
|
{
|
|
$this->oidcService = $oidcService;
|
|
$this->middleware('guard:oidc');
|
|
}
|
|
|
|
/**
|
|
* Start the authorization login flow via OIDC.
|
|
*/
|
|
public function login()
|
|
{
|
|
$loginDetails = $this->oidcService->login();
|
|
session()->flash('oidc_state', $loginDetails['state']);
|
|
|
|
return redirect($loginDetails['url']);
|
|
}
|
|
|
|
/**
|
|
* Authorization flow redirect.
|
|
* Processes authorization response from the OIDC Authorization Server.
|
|
*/
|
|
public function redirect(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');
|
|
}
|
|
|
|
$user = $this->oidcService->processAuthorizeResponse($request->query('code'));
|
|
if ($user === null) {
|
|
$this->showErrorNotification(trans('errors.oidc_fail_authed', ['system' => config('oidc.name')]));
|
|
return redirect('/login');
|
|
}
|
|
|
|
return redirect()->intended();
|
|
}
|
|
}
|