authenticateRequest not calling strategy for non get requests
I hope I did not get anything wrong, but this seems wrong A UserProfile in the sequence is only returned on get requests, not on post, put etc
Steps to reproduce
Create a authentication strategy and add something like that to the sequence
try {
await this.authenticateRequest(request);
} catch (e) {
if(e.code === AUTHENTICATION_STRATEGY_NOT_FOUND || e.code === USER_PROFILE_NOT_FOUND) {
throw new HttpErrors.Unauthorized(e.message);
} else {
throw e;
}
}
Current Behavior
await this.authenticateRequest(request);
will only return a UserProfile on get requests as well as the authenticate function of the strategy is not getting called.
Expected Behavior
for every request the authenticate function should get called and the UserProfile should be returned.
Additional information
The authetnicate function can be called manually as a work around.
await this.authenticateRequest(request);
let ba = new BasicAuthenticationStrategy();
user = await ba.authenticate(request);
@mmbabel , if you can provide a link to your github repo, we can help you better.
It is not clear that you've decorated your controller functions with the @authenticate(strategyName, options?) decorator.
@mmbabel , please see : https://loopback.io/doc/en/lb4/Loopback-component-authentication.html#using-the-authentication-decorator
@mmbabel
I cloned our shopping cart example
https://github.com/strongloop/loopback4-example-shopping
In /loopback4-example-shopping/packages/shopping/src/controllers/user.controller.ts
I added
@post('/users/uppercase/{textString}', {
responses: {
'200': {
description: '',
schema: {
type: 'string',
},
},
},
})
@authenticate('jwt')
async upperCase(@param.path.string('textString') textString: string): Promise<string> {
return textString.toUpperCase();
}
I tried it out, and it works.
Thanks @emonddr you were totally right, I was missing the controller annotation, sorry for this report
Thanks @emonddr you were totally right, I was missing the controller annotation, sorry for this report
No problem. :)