Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ABAC support and make custom actions more flexible #168

Merged
merged 3 commits into from
Jun 27, 2024

Conversation

Dallin343
Copy link
Contributor

Hello,

After filing the ticket #167, I decided to create a fork which adds the requested feature. ABAC models allow request parameters to be object or class instances instead of only strings, however, the current implementation of nest-authz requires strings. This means that ABAC models in Casbin are unusable. In this PR, I added support by doing the following:

  • I defined user and resource types AuthUser and AuthResource as string | Record<string, any>.
  • usernameFromContext has been changed to userFromContext which returns an AuthUser.

Additionally, in order to support more flexible naming of actions (especially in use cases without the concept of possession), I made possession optional:

  • I added an option called enablePosession to the module options that defaults to true if not provided.
  • I made possession optional in @UsePermissions and it defaults to AuthPossession.ANY
  • If possession is enabled, actions are still formatted as "{actionVerb}:{possession}". If possession is disabled, actions are formatted as "{actionVerb}".

Let me know what you think and if there are any improvements to make.

@casbin-bot
Copy link

@nodece @Shivansh-yadav13 please review

@Dallin343 Dallin343 changed the title Add ABAC support and make custom actions more flexible feat: Add ABAC support and make custom actions more flexible Jun 25, 2024
@CLAassistant
Copy link

CLAassistant commented Jun 25, 2024

CLA assistant check
All committers have signed the CLA.

@hsluoyz hsluoyz merged commit e0bc88f into node-casbin:master Jun 27, 2024
7 checks passed
github-actions bot pushed a commit that referenced this pull request Jun 27, 2024
# [2.9.0](v2.8.0...v2.9.0) (2024-06-27)

### Features

* Add ABAC support and make custom actions more flexible ([#168](#168)) ([e0bc88f](e0bc88f))
Copy link

🎉 This PR is included in version 2.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants