@@ -169,48 +169,58 @@ public function getAuthenticationService(ServerRequestInterface $request): Authe
169169 }
170170 $ service = new AuthenticationService ($ config );
171171
172+ // There are two possible login URLs. The default one is for HTML views.
173+ // And the other is for the in-progress mobile app.
174+ $ loginUrl = '/login ' ;
175+ if (($ request instanceof ServerRequest) && $ request ->getParam ('prefix ' ) == 'Api ' ) {
176+ $ loginUrl = '/api/tokens/add ' ;
177+ }
178+
172179 $ fields = [
173180 AbstractIdentifier::CREDENTIAL_USERNAME => 'email ' ,
174181 AbstractIdentifier::CREDENTIAL_PASSWORD => 'password ' ,
175182 ];
176- // Load identifiers
177- $ service -> loadIdentifier ( ' Authentication.Password ' , [
183+ $ passwordIdentifier = [
184+ ' fields ' => $ fields ,
178185 'resolver ' => [
179186 'className ' => 'Authentication.Orm ' ,
180187 'userModel ' => 'Users ' ,
181188 ],
182- 'fields ' => $ fields ,
183- ]);
184- $ service ->loadIdentifier ('ApiToken ' );
189+ ];
185190
186191 // Load the authenticators, you want session first
187192 $ service ->loadAuthenticator ('Authentication.Session ' , [
188193 'identify ' => true ,
189194 'fields ' => [
190195 AbstractIdentifier::CREDENTIAL_USERNAME => 'email ' ,
191196 ],
197+ 'identifier ' => [
198+ 'Authentication.Password ' => $ passwordIdentifier ,
199+ ],
192200 ]);
193201 $ service ->loadAuthenticator ('Authentication.Token ' , [
194202 'queryParam ' => 'token ' ,
195203 'header ' => 'Authorization ' ,
196204 'tokenPrefix ' => 'Bearer ' ,
205+ 'identifier ' => [
206+ 'ApiToken ' => [],
207+ // Necessary for token creation.
208+ 'Authentication.Password ' => $ passwordIdentifier ,
209+ ],
197210 ]);
198- // There are two possible login URLs. The default one is for HTML views.
199- // And the other is for the in-progress mobile app.
200- $ loginUrl = '/login ' ;
201- if (($ request instanceof ServerRequest) && $ request ->getParam ('prefix ' ) == 'Api ' ) {
202- $ loginUrl = '/api/tokens/add ' ;
203- }
204211 $ service ->loadAuthenticator ('Authentication.Form ' , [
212+ 'fields ' => $ fields ,
205213 'loginUrl ' => $ loginUrl ,
206- 'fields ' => [
207- AbstractIdentifier::CREDENTIAL_USERNAME => 'email ' ,
208- AbstractIdentifier::CREDENTIAL_PASSWORD => 'password ' ,
214+ 'identifier ' => [
215+ 'Authentication.Password ' => $ passwordIdentifier ,
209216 ],
210217 ]);
211218 $ service ->loadAuthenticator ('Authentication.Cookie ' , [
212219 'fields ' => $ fields ,
213220 'loginUrl ' => '/login ' ,
221+ 'identifier ' => [
222+ 'Authentication.Password ' => $ passwordIdentifier ,
223+ ],
214224 ]);
215225
216226 return $ service ;
0 commit comments