3.2.1 • Published 7 months ago

@antify/authorization-module v3.2.1

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

Authorization Module

This module is responsible for handling user authorization using JWT. It ships with a set of components and utils to make it easy to integrate authorization into your application. It also supports multitenancy.

Architecture

This module supports different permissions in different multi-tenant instances. All permissions should be stored in one application instance.

To encapsulate the authorization logic from your main application, this module provides an Authorization object. Extend your applications Account or User model with the Authorization object to extend your app with authorization functionality.

Permission

There's a global set of permissions. An authorization can have multiple permissions for each tenant.

Role

To make the usage of permissions easier, there are roles. A role can have multiple permissions. Each tenant have it own set of roles.

Admin

An authorization can be an admin. An admin has all permissions independent of the associated permissions.

Ban

An authorization can be banned.

The isBan flag always is more important than the isAdmin flag. E. g.: A banned user has no permissions, even if he is an admin.

An authenticated user always get a valid token, even he's banned. This gives the possibility to redirect him to login page OR show him a jail page.

Access hierarchy

To emit if an authorization has access with a specific permission, following hierarchy is used:

  • Is banned
  • Is admin
  • Has permission

TODO::

  • Add validator which check the tokens structure on runtime.
  • Add refresh token process
  • Add access token process
  • Cleanup module.ts
  • Composable to reach all permissions in system
  • Find a way to handle permissions properly across modules
  • Force logout or refresh token function to logout/ban all devices fast

Usage

Installation

pnpm i @antify/authorization-module

Add it to your nuxt.config.ts:

export default {
  modules: [
    '@antify/authorization-module'
  ]
}

Configuration

TODO

Components

TODO:: Describe it

AuthorizationModuleBanAuthorizationButton

Button to ban and unban a user.

It does:

  • Switch between ban and unban
  • Does not allow a user to ban / unban himself
  • Check if the user has the expected permission to ban / unban (CAN_BAN_AUTHORIZATION | CAN_UNBAN_AUTHORIZATION | is an admin)

AuthorizationModuleJailPage

A default jail page to show a user that he is banned.

Important

Populate the authorization.roles

Because .roles is a relation to the roles table, you need to populate it. Also be careful, you need to add the model property to the populate method, because @antify/database is a multi connection client. To make mongoose work properly, you need to specify the model. Read more about it here.

const user = await UserModel
  .findOne({_id: userId})
  .populate({
    path: 'authorization.roles',
    model: client.getModel(defineRoleSchema)
  });

Development

  • Run pnpm run dev:prepare to generate type stubs.
  • Use pnpm run dev to start playground in development mode.
1.2.0

1 year ago

1.2.1

10 months ago

2.3.0

9 months ago

2.1.2

9 months ago

2.2.0

9 months ago

2.1.1

9 months ago

2.3.2

8 months ago

2.3.1

9 months ago

2.1.3

9 months ago

2.3.3

8 months ago

2.1.0

9 months ago

2.0.0

9 months ago

3.1.3

7 months ago

3.2.1

7 months ago

3.1.2

7 months ago

3.2.0

7 months ago

3.1.1

7 months ago

3.1.0

7 months ago

3.0.0

7 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.0

2 years ago