]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/Auth/Saml2Controller.php
Started using OneLogin SAML lib directly
[bookstack] / app / Http / Controllers / Auth / Saml2Controller.php
1 <?php
2
3 namespace BookStack\Http\Controllers\Auth;
4
5 use BookStack\Auth\Access\Saml2Service;
6 use BookStack\Http\Controllers\Controller;
7 use Illuminate\Http\Request;
8
9 class Saml2Controller extends Controller
10 {
11
12     protected $samlService;
13
14     /**
15      * Saml2Controller constructor.
16      */
17     public function __construct(Saml2Service $samlService)
18     {
19         parent::__construct();
20         $this->samlService = $samlService;
21     }
22
23     /**
24      * Start the login flow via SAML2.
25      */
26     public function login()
27     {
28         $loginDetails = $this->samlService->login();
29         session()->flash('saml2_request_id', $loginDetails['id']);
30
31         return redirect($loginDetails['url']);
32     }
33
34     /*
35      * Get the metadata for this SAML2 service provider.
36      */
37     public function metadata()
38     {
39         $metaData = $this->samlService->metadata();
40         return response()->make($metaData, 200, [
41             'Content-Type' => 'text/xml'
42         ]);
43     }
44
45     /**
46      * Single logout service.
47      * Handle logout requests and responses.
48      */
49     public function sls()
50     {
51         // TODO
52     }
53
54     /**
55      * Assertion Consumer Service.
56      * Processes the SAML response from the IDP.
57      */
58     public function acs()
59     {
60         $requestId = session()->pull('saml2_request_id', null);
61
62         $user = $this->samlService->processAcsResponse($requestId);
63         if ($user === null) {
64             $this->showErrorNotification(trans('errors.saml_fail_authed', ['system' => config('saml2.name')]));
65             return redirect('/login');
66         }
67
68         return redirect()->intended();
69     }
70
71 }