0.2.0 • Published 9 months ago

@mest-fe/nestjs-sso v0.2.0

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

NestJS SSO

Common authentication SDK for internal services (NestJS project).

Installation

  1. Install package: yarn add @mest-fe/nestjs-sso
  2. Add SSOModule.forRoot() to your module imports.

Usage

Authentication

Add a decorator to any controller class or method, and the user will be authenticated before the method is called.

// controller
@MestAuth()
@Controller('/users')
export class UsersController {
}

// method
@MestAuth()
@Post('/login')
async login() {
  return 'ok'
}

Scope

Specify roles for controller classes or methods:

// Require authenticated and admin role
@MestRoleAuth(MestRoles.ADMIN)
@Delete('/users')
async removeUsers() {
  return 'ok'
}

Get current user

On any controller method, the user of the current session can be injected:

@Get('/users/self')
@MestAuth()
async getSelf(@MestUser() user: MestUserType){
  return user
}

Errors

When a user without a session request an api that requires authentication, a 401 error will be returned in http; If the user simply has a role that does not match, a 403 error will be thrown.

The server will not handle these errors and you should direct the user on the client side to the sso.mest.sh to log in.

0.3.0-dev.1

9 months ago

0.3.0-dev.0

9 months ago

0.2.0

1 year ago

0.1.2-dev.1

2 years ago

0.1.2-dev.0

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.0.3

2 years ago

0.1.1

2 years ago

0.0.2

2 years ago

0.0.5

2 years ago

0.1.3

2 years ago

0.0.4

2 years ago

0.0.6

2 years ago

0.0.1

2 years ago