inversify-express-utils icon indicating copy to clipboard operation
inversify-express-utils copied to clipboard

It defines an IsAuthenticated decorator that is applied to routes.

Open victor-shelepen opened this issue 6 years ago • 6 comments

IsAuthenticated decorator has been created that is applied to route actions.

Description

There is functionality that provides authorization functionality. There are examples in imperative way these show how to use it. But it likes configurable rules. Principal has also to provide its functionality in a declarative way by decorators. I have not also found an example of decorator usage

Related Issue

inversify-express-utils - An example of a custom decorator. Cover the Principal functionality with decorators.

Motivation and Context

It will provide the functionality in a declarative style. The project will provide functionality by configurable rules. It is convenient and structural approach.

How Has This Been Tested?

Expected Behavior

  @httpGet('/acl/:_id')
  @permission('fetch_any_acl')
  private async acl (request: Request) {
    const hasAccess = await this.httpContext.user.isResourceOwner('fetch_any_acl')
    if (!hasAccess) {
      return this.json({ message: 'Forbidden' }, 403)
    }
    const userData = await this.userEntity.getFull(new ObjectId(request.params._id))

    return this.json(userData, 200)
  }

Current Behavior

  @httpGet('/acl/:_id')
  @permission('fetch_any_acl')
  private async acl (request: Request) {
    const userData = await this.userEntity.getFull(new ObjectId(request.params._id))

    return this.json(userData, 200)
  }

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [ ] My code follows the code style of this project.
  • [x] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [x] I have read the CONTRIBUTING document.
  • [x] I have added tests to cover my changes.
  • [x] All new and existing tests passed.

victor-shelepen avatar Dec 18 '18 14:12 victor-shelepen

thanks for the PR. Could you please update the documentation to explain the use case and how to use it.

Thank you

dcavanagh avatar Jan 04 '19 17:01 dcavanagh

@dcavanagh Yes, I will do. :)

victor-shelepen avatar Jan 07 '19 16:01 victor-shelepen

@dcavanagh I've added the documentation. It is available here. The decorators are applied only on actions now. We can also extend the functionality for controllers. This is a good idea to disclose how to implement custom decorators for controllers and actions in documentation.

victor-shelepen avatar Jan 07 '19 19:01 victor-shelepen

hey @victor-shelepen if you can get this green with master and address some of the comments I'll happily merge this

PodaruDragos avatar Aug 25 '21 10:08 PodaruDragos

@dcavanagh I've added the documentation. It is available here. The decorators are applied only on actions now. We can also extend the functionality for controllers. This is a good idea to disclose how to implement custom decorators for controllers and actions in documentation.

Will be great if we can have this for controllers as well

PodaruDragos avatar Aug 25 '21 10:08 PodaruDragos

hey @victor-shelepen if you can get this green with master and address some of the comments I'll happily merge this

:) Thank you. I agree.

victor-shelepen avatar Sep 14 '21 15:09 victor-shelepen