File tree Expand file tree Collapse file tree 3 files changed +33
-5
lines changed
Expand file tree Collapse file tree 3 files changed +33
-5
lines changed Original file line number Diff line number Diff line change @@ -111,8 +111,12 @@ public function getAdminUri(
111111 );
112112 }
113113
114- public function getLogoutUri ():UriInterface {
115- return new LogoutUri ($ this ->authwaveHost );
114+ public function getLogoutUri (string $ returnToPath = null ):UriInterface {
115+ if (is_null ($ returnToPath )) {
116+ $ returnToPath = $ this ->currentUriPath ;
117+ }
118+
119+ return new LogoutUri ($ this ->authwaveHost , $ returnToPath );
116120 }
117121
118122 private function completeAuth ():void {
Original file line number Diff line number Diff line change 44class LogoutUri extends AbstractProviderUri {
55 const PATH_LOGOUT = "/logout " ;
66
7- public function __construct (string $ baseRemoteUri ) {
7+ public function __construct (
8+ string $ baseRemoteUri ,
9+ string $ returnToUri = "/ "
10+ ) {
811 $ baseRemoteUri = $ this ->normaliseBaseUri ($ baseRemoteUri );
912 parent ::__construct ($ baseRemoteUri );
1013 $ this ->path = self ::PATH_LOGOUT ;
14+ $ this ->query = http_build_query ([
15+ "returnTo " => $ returnToUri ,
16+ ]);
1117 }
1218}
Original file line number Diff line number Diff line change @@ -73,24 +73,42 @@ public function testLogoutClearsSession() {
7373 Authenticator::SESSION_KEY => $ sessionData
7474 ];
7575
76+ $ redirectHandler = self ::createMock (RedirectHandler::class);
77+
78+ $ sut = new Authenticator (
79+ "example-app-id " ,
80+ "test-key " ,
81+ "/ " ,
82+ AuthUri::DEFAULT_BASE_REMOTE_URI ,
83+ null ,
84+ $ redirectHandler
85+ );
86+ $ sut ->logout ();
87+ self ::assertEmpty ($ _SESSION );
88+ }
89+
90+ public function testLogoutRedirectsToCurrentPath () {
91+ $ _SESSION = [];
92+ $ currentPath = "/current/example/path " ;
93+
7694 $ redirectHandler = self ::createMock (RedirectHandler::class);
7795 $ redirectHandler ->expects (self ::once ())
7896 ->method ("redirect " )
7997 ->with (self ::callback (fn (UriInterface $ uri ) =>
8098 $ uri ->getHost () === AuthUri::DEFAULT_BASE_REMOTE_URI
8199 && $ uri ->getPath () === LogoutUri::PATH_LOGOUT
100+ && $ uri ->getQuery () === "returnTo= " . urlencode ($ currentPath )
82101 ));
83102
84103 $ sut = new Authenticator (
85104 "example-app-id " ,
86105 "test-key " ,
87- " / " ,
106+ $ currentPath ,
88107 AuthUri::DEFAULT_BASE_REMOTE_URI ,
89108 null ,
90109 $ redirectHandler
91110 );
92111 $ sut ->logout ();
93- self ::assertEmpty ($ _SESSION );
94112 }
95113
96114 public function testLoginRedirects () {
You can’t perform that action at this time.
0 commit comments