]> BookStack Code Mirror - bookstack/blob - app/Listeners/Saml2LoginEventListener.php
Add login and automatic registration; Prepare Group sync
[bookstack] / app / Listeners / Saml2LoginEventListener.php
1 <?php namespace BookStack\Listeners;
2
3 use BookStack\Auth\Access\Saml2Service;
4 use Illuminate\Queue\InteractsWithQueue;
5 use Illuminate\Contracts\Queue\ShouldQueue;
6 use Aacotroneo\Saml2\Events\Saml2LoginEvent;
7 use Illuminate\Support\Facades\Log;
8
9 class Saml2LoginEventListener
10 {
11     protected $saml;
12
13     /**
14      * Create the event listener.
15      *
16      * @return void
17      */
18     public function __construct(Saml2Service $saml)
19     {
20         $this->saml = $saml;
21     }
22
23     /**
24      * Handle the event.
25      *
26      * @param  Saml2LoginEvent  $event
27      * @return void
28      */
29     public function handle(Saml2LoginEvent $event)
30     {
31         $messageId = $event->getSaml2Auth()->getLastMessageId();
32         // TODO: Add your own code preventing reuse of a $messageId to stop replay attacks
33
34         $samlUser = $event->getSaml2User();
35
36         $attrs = $samlUser->getAttributes();
37         $id    = $samlUser->getUserId();
38         //$assertion = $user->getRawSamlAssertion()
39
40         $user = $this->saml->processLoginCallback($id, $attrs);
41     }
42 }