New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@tc-libs/authentication

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tc-libs/authentication

Layer di autenticazione/autorizzazione per NestJS basato su JWT, permission token e OAuth opzionale Google/Apple.

latest
npmnpm
Version
3.9.0
Version published
Weekly downloads
163
136.23%
Maintainers
1
Weekly downloads
 
Created
Source

@tc-libs/authentication

Layer di autenticazione/autorizzazione per NestJS basato su JWT, permission token e OAuth opzionale Google/Apple.

Il package esporta:

  • AuthModule
  • AuthService
  • decorator per protezione endpoint
  • guard e strategy
  • enum ENUM_AUTH_ACCESS_FOR

Prerequisito importante

AuthService dipende da PasswordService e TokenService di @tc-libs/helper. In pratica questo package va usato insieme a HelperModule.

Registrazione

AuthModule.register(
  {
    jwt: {
      defaultSecretKey: process.env.JWT_DEFAULT_SECRET!,
      defaultExpirationTime: 3600,
    },
    auth: {
      prefixAuthorization: 'Bearer',
      subject: 'access',
      audience: 'my-api',
      issuer: 'my-service',
      payloadEncryption: true,
      accessToken: {
        secretKey: process.env.ACCESS_TOKEN_SECRET!,
        expirationTime: 3600,
        notBeforeExpirationTime: 0,
        encryptKey: process.env.ACCESS_TOKEN_ENCRYPT_KEY!,
        encryptIv: process.env.ACCESS_TOKEN_ENCRYPT_IV!,
      },
      refreshToken: {
        secretKey: process.env.REFRESH_TOKEN_SECRET!,
        expirationTime: 86400,
        expirationTimeRememberMe: 2592000,
        notBeforeExpirationTime: 0,
        encryptKey: process.env.REFRESH_TOKEN_ENCRYPT_KEY!,
        encryptIv: process.env.REFRESH_TOKEN_ENCRYPT_IV!,
      },
      permissionToken: {
        headerName: 'x-permission-token',
        secretKey: process.env.PERMISSION_TOKEN_SECRET!,
        expirationTime: 900,
        notBeforeExpirationTime: 0,
        encryptKey: process.env.PERMISSION_TOKEN_ENCRYPT_KEY!,
        encryptIv: process.env.PERMISSION_TOKEN_ENCRYPT_IV!,
      },
    },
  },
  true,
);

Le strategy Google e Apple vengono registrate solo se la relativa configurazione e completa.

AuthService

Metodi principali:

  • getAuthToken(payload, rememberMe)
  • getRefreshToken(payload, refreshToken, rememberMe, loginDate)
  • validateUser(password, hash)
  • createPassword(password)
  • getter per scadenze, issuer, audience, subject

Esempio login:

const token = await this.authService.getAuthToken(
  { _id: user._id.toString(), email: user.email, role: user.role },
  false,
);

Decorator utili

  • AuthJwtAccessProtected()
  • AuthJwtRefreshProtected()
  • AuthJwtPublicAccessProtected()
  • AuthJwtAdminAccessProtected()
  • AuthPermissionProtected(group, ...permissions)
  • CurrentUser()
  • User()
  • AuthJwtPayload()
  • AuthJwtToken()

Esempio:

@Get('me')
@AuthJwtAccessProtected()
profile(@CurrentUser() user: any) {
  return user;
}

Access levels

Il package definisce:

  • SUPER_ADMIN
  • USER
  • ADMIN
  • EDITOR
  • LOGISTIC

Questi valori vengono riusati da role, api-key e altri package.

Sviluppo

nx build authentication
nx test authentication

FAQs

Package last updated on 01 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts