npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@antify/authorization-module

v1.1.1

Published

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.

Downloads

8

Readme

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.

Architecture

This module supports different permissions in different multi-tenant applications. 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 app and tenant.

Role

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

Admin

An authorization can be an admin in two ways:

  • System-wide
  • Per tenant

Ban

An authorization can be banned in two ways:

  • System-wide
  • Per tenant

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 or super admin.

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

A banned authorization for a specific tenant also get a valid token to give him access to other tenants where he is not banned.

Access hierarchy

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

  • System-wide ban
  • Is super admin
  • Is banned in app
  • Is admin in app
  • Has permission in app

TODO::

  • [ ] Add validator which check the tokens structure on runtime.
  • [ ] Make sure that a AppAccess appId and tenantId is the same as the roles appId and tenantId
  • [ ] Add refresh token process
  • [ ] Add access token process
  • [ ] Cleanup module.ts
  • [ ] Select multiple Roles components
  • [ ] Add roles CRUD
  • [ ] Composable to reach all permissions in system
  • [ ] Find a way to handle permissions properly across modules
  • [ ] Fix and add tests
  • [ ] 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 system-wide.

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 | is an super admin)

AuthorizationModuleBanAppAccessButton

Button to ban and unban a user from an app instance.

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_PROVIDER_ACCESS | CAN_UNBAN_PROVIDER_ACCESS | is an admin | is a super admin)
  • Check if the user has the expected permission to ban / unban an administrator (CAN_BAN_ADMIN_PROVIDER_ACCESS | CAN_UNBAN_ADMIN_PROVIDER_ACCESS | is an admin | is a super admin)

AuthorizationModuleJailPage

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

Important

Populate the authorization.appAccesses.roles

Because appAccesses.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.appAccesses.roles',
    model: client.getModel<Role>('authorization_roles')
  });

Development

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