@@ -114,36 +114,38 @@ public function __invoke(
114
114
return $ response ;
115
115
}
116
116
117
+ public $ lastProcessingResult ;
118
+
117
119
public function process (
118
120
ServerRequestInterface $ request ,
119
121
RequestHandlerInterface $ handler
120
122
): ResponseInterface
121
123
{
122
- $ auth_result = $ this ->authenticatedUsingAdapters ($ request );
124
+ $ this -> lastProcessingResult = $ this ->authenticatedUsingAdapters ($ request );
123
125
124
- if ($ auth_result instanceof TransportInterface
125
- && !$ auth_result ->isEmpty ()
126
+ if ($ this -> lastProcessingResult instanceof TransportInterface
127
+ && !$ this -> lastProcessingResult ->isEmpty ()
126
128
) {
127
- if ($ auth_result instanceof AuthenticationTransportInterface) {
128
- $ this ->setAuthenticatedUser ($ auth_result ->getAuthenticatedUser ());
129
- $ this ->setAuthenticatedWith ($ auth_result ->getAuthenticatedWith ());
129
+ if ($ this -> lastProcessingResult instanceof AuthenticationTransportInterface) {
130
+ $ this ->setAuthenticatedUser ($ this -> lastProcessingResult ->getAuthenticatedUser ());
131
+ $ this ->setAuthenticatedWith ($ this -> lastProcessingResult ->getAuthenticatedWith ());
130
132
131
133
$ this ->triggerEvent (
132
134
'user_authenticated ' ,
133
- $ auth_result ->getAuthenticatedUser (),
134
- $ auth_result ->getAuthenticatedWith ()
135
+ $ this -> lastProcessingResult ->getAuthenticatedUser (),
136
+ $ this -> lastProcessingResult ->getAuthenticatedWith ()
135
137
);
136
138
}
137
139
138
- $ request = $ auth_result ->applyToRequest ($ request );
140
+ $ request = $ this -> lastProcessingResult ->applyToRequest ($ request );
139
141
}
140
142
141
143
$ response = $ handler ->handle ($ request );
142
144
143
- if ($ auth_result instanceof TransportInterface
144
- && !$ auth_result ->isEmpty ()
145
+ if ($ this -> lastProcessingResult instanceof TransportInterface
146
+ && !$ this -> lastProcessingResult ->isEmpty ()
145
147
) {
146
- $ response = $ auth_result ->applyToResponse ($ response );
148
+ $ response = $ this -> lastProcessingResult ->applyToResponse ($ response );
147
149
}
148
150
149
151
return $ response ;
@@ -158,11 +160,14 @@ public function authorize(
158
160
{
159
161
try {
160
162
$ user = $ authorizer ->verifyCredentials ($ credentials );
161
- $ authenticated_with = $ adapter ->authenticate ($ user , $ credentials );
163
+ $ authenticatedWith = $ adapter ->authenticate ($ user , $ credentials );
162
164
163
- $ this ->triggerEvent ('user_authorized ' , $ user , $ authenticated_with );
165
+ $ this ->triggerEvent ('user_authorized ' , $ user , $ authenticatedWith );
164
166
165
- return new AuthorizationTransport ($ adapter , $ user , $ authenticated_with , $ payload );
167
+ $ authorizationResult = new AuthorizationTransport ($ adapter , $ user , $ authenticatedWith , $ payload );
168
+ $ this ->lastProcessingResult = $ authorizationResult ;
169
+
170
+ return $ authorizationResult ;
166
171
} catch (Exception $ e ) {
167
172
$ this ->triggerEvent ('user_authorization_failed ' , $ credentials , $ e );
168
173
@@ -172,14 +177,18 @@ public function authorize(
172
177
173
178
public function terminate (
174
179
AdapterInterface $ adapter ,
175
- AuthenticationResultInterface $ authenticated_with
180
+ AuthenticationResultInterface $ authenticatedWith
176
181
): TransportInterface
177
182
{
178
- $ termination_result = $ adapter ->terminate ($ authenticated_with );
183
+ $ terminationResult = $ adapter ->terminate ($ authenticatedWith );
184
+
185
+ $ this ->setAuthenticatedUser (null );
186
+ $ this ->setAuthenticatedWith (null );
179
187
180
- $ this ->triggerEvent ('user_deauthenticated ' , $ authenticated_with );
188
+ $ this ->triggerEvent ('user_deauthenticated ' , $ authenticatedWith );
189
+ $ this ->lastProcessingResult = $ terminationResult ;
181
190
182
- return $ termination_result ;
191
+ return $ terminationResult ;
183
192
}
184
193
185
194
/**
@@ -242,7 +251,7 @@ public function getAuthenticatedWith(): ?AuthenticationResultInterface
242
251
return $ this ->authenticated_with ;
243
252
}
244
253
245
- public function setAuthenticatedWith (AuthenticationResultInterface $ value ): AuthenticationInterface
254
+ public function setAuthenticatedWith (? AuthenticationResultInterface $ value ): AuthenticationInterface
246
255
{
247
256
$ this ->authenticated_with = $ value ;
248
257
0 commit comments