File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -211,12 +211,16 @@ export class AuthenticationBase {
211
211
async authenticate ( authentication : AuthenticationRequest , params : Params , ...allowed : string [ ] ) {
212
212
const { strategy } = authentication || ( { } as AuthenticationRequest ) ;
213
213
const [ authStrategy ] = this . getStrategies ( strategy ) ;
214
+ const strategyAllowed = allowed . includes ( strategy ) ;
214
215
215
216
debug ( 'Running authenticate for strategy' , strategy , allowed ) ;
216
217
217
- if ( ! authentication || ! authStrategy || ! allowed . includes ( strategy ) ) {
218
+ if ( ! authentication || ! authStrategy || ! strategyAllowed ) {
219
+ const additionalInfo = ( ! strategy && ' (no `strategy` set)' ) ||
220
+ ( ! strategyAllowed && ' (strategy not allowed in authStrategies)' ) || '' ;
221
+
218
222
// If there are no valid strategies or `authentication` is not an object
219
- throw new NotAuthenticated ( ` Invalid authentication information` + ( ! strategy ? ' (no `strategy` set)' : '' ) ) ;
223
+ throw new NotAuthenticated ( ' Invalid authentication information' + additionalInfo ) ;
220
224
}
221
225
222
226
return authStrategy . authenticate ( authentication , {
Original file line number Diff line number Diff line change @@ -190,7 +190,7 @@ describe('authentication/core', () => {
190
190
assert . fail ( 'Should never get here' ) ;
191
191
} catch ( error ) {
192
192
assert . strictEqual ( error . name , 'NotAuthenticated' ) ;
193
- assert . strictEqual ( error . message , 'Invalid authentication information' ) ;
193
+ assert . strictEqual ( error . message , 'Invalid authentication information (strategy not allowed in authStrategies) ' ) ;
194
194
}
195
195
} ) ;
196
196
You can’t perform that action at this time.
0 commit comments