loopbackio / loopbackio/loopback-next
How to report HttpErrors.Forbidden from authenticate action
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
Suggestion
I have implement JWTStrategy
every thing working fine. now I am trying to further authenticate according to user roles
e.g if logged in user is not `ADMIN` raised `HttpErrors.Forbidden` error
current strategy-adapter.js code only raise InternalServerError if I pass error in cb() of JWTStrategy
I have changed strategy-adapter.js
`reject(new rest_1.HttpErrors.InternalServerError(error));` to
`reject(error);` and pass
`cb(new HttpErrors.Forbidden(), false);` in `auth-strategy.provides.ts`
which working according to my requirement
my question is there best way to implement changes in my code instead of changing in @loopback/authentication module directly
Existing CODE
`@loopback/authentication/strategy-adapter.js `
```js
strategy.error = function (error) {
reject(new rest_1.HttpErrors.InternalServerError(error));
};
```
Contributor guide
Research direction
Start by reading @loopback/authentication/strategy-adapter.js and the auth-strategy.provides.ts callback usage shown in the issue. Trace how strategy errors become HTTP errors and determine what supported extension point would preserve HttpErrors.Forbidden without editing the module directly; done means the role-authentication error is propagated through the documented application code path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- authentication
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100