11<?php
22namespace Authwave ;
33
4+ use Authwave \ProviderUri \AbstractProviderUri ;
45use Authwave \ProviderUri \AdminUri ;
56use Authwave \ProviderUri \AuthUri ;
67use Authwave \ProviderUri \LogoutUri ;
1112class Authenticator {
1213 const SESSION_KEY = "AUTHWAVE_SESSION " ;
1314 const RESPONSE_QUERY_PARAMETER = "AUTHWAVE_RESPONSE_DATA " ;
15+ const LOGIN_TYPE_DEFAULT = "login-default " ;
16+ const LOGIN_TYPE_ADMIN = "login-admin " ;
1417
1518 private string $ clientKey ;
1619 private string $ currentUriPath ;
@@ -59,7 +62,10 @@ public function isLoggedIn():bool {
5962 return isset ($ userData );
6063 }
6164
62- public function login (Token $ token = null ):void {
65+ public function login (
66+ Token $ token = null ,
67+ string $ loginType = self ::LOGIN_TYPE_DEFAULT
68+ ):void {
6369 if ($ this ->isLoggedIn ()) {
6470 return ;
6571 }
@@ -71,17 +77,18 @@ public function login(Token $token = null):void {
7177 $ this ->sessionData = new SessionData ($ token );
7278 $ this ->session ->set (self ::SESSION_KEY , $ this ->sessionData );
7379
74- $ this ->redirectHandler ->redirect ($ this ->getAuthUri ($ token ));
80+ $ this ->redirectHandler ->redirect (
81+ $ this ->getAuthUri ($ token , $ loginType )
82+ );
7583 }
7684
7785 public function logout ():void {
7886// TODO: Should the logout redirect the user agent to the redirectPath?
7987 $ this ->session ->remove (self ::SESSION_KEY );
80- $ this ->redirectHandler ->redirect ($ this ->getLogoutUri ());
8188 }
8289
83- public function adminLogin ():void {
84- // TODO: Implement!
90+ public function adminLogin (Token $ token = null ):void {
91+ $ this -> login ( $ token , self :: LOGIN_TYPE_ADMIN );
8592 }
8693
8794 public function getUuid ():string {
@@ -94,7 +101,22 @@ public function getEmail():string {
94101 return $ userData ->getEmail ();
95102 }
96103
97- public function getAuthUri (Token $ token ):AuthUri {
104+ public function getField (string $ name ):?string {
105+ $ userData = $ this ->sessionData ->getUserData ();
106+ return $ userData ->getField ($ name );
107+ }
108+
109+ public function getAuthUri (
110+ Token $ token ,
111+ string $ loginType = self ::LOGIN_TYPE_DEFAULT
112+ ):AbstractProviderUri {
113+ if ($ loginType === self ::LOGIN_TYPE_ADMIN ) {
114+ return new AdminUri (
115+ $ this ->currentUriPath ,
116+ $ this ->authwaveHost
117+ );
118+ }
119+
98120 return new AuthUri (
99121 $ token ,
100122 $ this ->currentUriPath ,
@@ -111,12 +133,13 @@ public function getAdminUri(
111133 );
112134 }
113135
114- public function getLogoutUri (string $ returnToPath = null ):UriInterface {
115- if (is_null ($ returnToPath )) {
116- $ returnToPath = (new Uri ($ this ->currentUriPath ))->getPath ();
117- }
118-
119- return new LogoutUri ($ this ->authwaveHost , $ returnToPath );
136+ public function getProfileUri (
137+ string $ path = ProfileUri::PATH_PROFILE
138+ ):UriInterface {
139+ return new ProfileUri (
140+ $ this ->authwaveHost ,
141+ $ path
142+ );
120143 }
121144
122145 private function completeAuth ():void {
0 commit comments