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 {
211211 async authenticate ( authentication : AuthenticationRequest , params : Params , ...allowed : string [ ] ) {
212212 const { strategy } = authentication || ( { } as AuthenticationRequest ) ;
213213 const [ authStrategy ] = this . getStrategies ( strategy ) ;
214+ const strategyAllowed = allowed . includes ( strategy ) ;
214215
215216 debug ( 'Running authenticate for strategy' , strategy , allowed ) ;
216217
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+
218222 // 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 ) ;
220224 }
221225
222226 return authStrategy . authenticate ( authentication , {
Original file line number Diff line number Diff line change @@ -190,7 +190,7 @@ describe('authentication/core', () => {
190190 assert . fail ( 'Should never get here' ) ;
191191 } catch ( error ) {
192192 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) ' ) ;
194194 }
195195 } ) ;
196196
You can’t perform that action at this time.
0 commit comments