]> BookStack Code Mirror - bookstack/blob - app/Auth/Access/Guards/OpenIdSessionGuard.php
Started refactor for merge of OIDC
[bookstack] / app / Auth / Access / Guards / OpenIdSessionGuard.php
1 <?php
2
3 namespace BookStack\Auth\Access\Guards;
4
5 use BookStack\Auth\Access\OpenIdService;
6 use BookStack\Auth\Access\RegistrationService;
7 use Illuminate\Contracts\Auth\UserProvider;
8 use Illuminate\Contracts\Session\Session;
9
10 /**
11  * OpenId Session Guard
12  *
13  * The OpenId login process is async in nature meaning it does not fit very well
14  * into the default laravel 'Guard' auth flow. Instead most of the logic is done
15  * via the OpenId controller & OpenIdService. This class provides a safer, thin
16  * version of SessionGuard.
17  *
18  * @package BookStack\Auth\Access\Guards
19  */
20 class OpenIdSessionGuard extends ExternalBaseSessionGuard
21 {
22
23     protected $openidService;
24
25     /**
26      * OpenIdSessionGuard constructor.
27      */
28     public function __construct(
29         $name,
30         UserProvider $provider,
31         Session $session,
32         OpenIdService $openidService,
33         RegistrationService $registrationService
34     ) {
35         $this->openidService = $openidService;
36         parent::__construct($name, $provider, $session, $registrationService);
37     }
38
39     /**
40      * Get the currently authenticated user.
41      *
42      * @return \Illuminate\Contracts\Auth\Authenticatable|null
43      */
44     public function user()
45     {
46         // retrieve the current user
47         $user = parent::user();
48
49         // refresh the current user
50         if ($user && !$this->openidService->refresh()) {
51             $this->user = null;
52         }
53
54         return $this->user;
55     }
56
57     /**
58      * Validate a user's credentials.
59      *
60      * @param array $credentials
61      * @return bool
62      */
63     public function validate(array $credentials = [])
64     {
65         return false;
66     }
67
68     /**
69      * Attempt to authenticate a user using the given credentials.
70      *
71      * @param array $credentials
72      * @param bool $remember
73      * @return bool
74      */
75     public function attempt(array $credentials = [], $remember = false)
76     {
77         return false;
78     }
79 }