New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@edirect/auth

Package Overview
Dependencies
Maintainers
26
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@edirect/auth

Auth Module

  • 9.1.0
  • npm
  • Socket score

Version published
Weekly downloads
155
increased by66.67%
Maintainers
26
Weekly downloads
 
Created
Source

@edirect/auth

The EDirectInsure Auth Module.

Installation

$ npm i --save @edirect/auth

Usage

// app.module.ts
import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import { APP_GUARD } from '@nestjs/core';
import { AuthGuard, AuthMiddleware } from '@edirect/auth';

@Module({
  providers: [
    //...
    {
      provide: APP_GUARD,
      useFactory: (configService: ConfigService, reflector: Reflector) => new AuthGuard(configService, reflector),
      inject: [ConfigService, Reflector]
    },
    //...
  ],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer): void {
    consumer.apply(AuthMiddleware).forRoutes('cats');
  }
}

// cats.controller.ts
import { Controller, Get } from '@nestjs/common';
import { Roles, Permissions } from '@edirect/auth';

@Controller('cats')
export class CatsController {
  @Get()
  @Resources('Default Resource')
  @Roles('ROLE_USER')
  @Permissions('CATS.READ')
  findAll(): Promise<Response> {
    return [];
  }
}
# .{NODE_ENV}.ENV
KEYCLOAK_BASE_URL=http://keycloak-base-url
KEYCLOAK_REALM=keycloak_realm
KEYCLOAK_CLIENT=your-app-client
AUTH_SERVICE_JWKS=https://auth-service-base-url/oidc/jwks

Sample Testing

  1. Start Keycloak: docker-compose -f .\keycloak\docker-compose.yml up -d;
  2. Start Sample project as in the documentation,
  3. Run the command: curl --location --request GET 'http://0.0.0.0:3000' \ --header 'Authorization: Bearer eyJhbG...Md2wDw';
// Output curl
{
    "user": {
        "aud": "sample-client",
        "exp": 1674548742,
        "iat": 1674548442,
        "iss": "http://0.0.0.0:8080/realms/main",
        "jti": "0fa1627d-ca89-4a08-b2a5-5ab97b21fbbb",
        "permissions": [
            "offline_access",
            "uma_authorization",
            "default-roles-main"
        ],
        "roles": [],
        "scope": "openid profile email entities phone",
        "username": "adailson.moreira@bolttech.io",
        "entityUser": {
            "email": "adailson.moreira@bolttech.io",
            "firstName": "Adailson",
            "lastName": "Moreiraa",
            "phone": "972367087"
        }
    },
    "rolesToCheck": [
        "ROLE_USER"
    ],
    "roleToCheck": "ROLE_USER",
    "permissionsToCheck": [
        "ENTITY.READ",
        "ENTITY.READ_ONLY_OWN"
    ],
    "permissionToCheck": "ENTITY.READ",
    "auth": {
        "getToken": "eyJhbG...Md2wDw",
        "getUser": {
            "aud": "sample-client",
            "exp": 1674548742,
            "iat": 1674548442,
            "iss": "http://0.0.0.0:8080/realms/main",
            "jti": "0fa1627d-ca89-4a08-b2a5-5ab97b21fbbb",
            "permissions": [
                "offline_access",
                "uma_authorization",
                "default-roles-main"
            ],
            "roles": [],
            "scope": "openid profile email entities phone",
            "username": "adailson.moreira@bolttech.io",
            "entityUser": {
                "email": "adailson.moreira@bolttech.io",
                "firstName": "Adailson",
                "lastName": "Moreiraa",
                "phone": "972367087"
            }
        },
        "getEntityUser": {
            "email": "adailson.moreira@bolttech.io",
            "firstName": "Adailson",
            "lastName": "Moreiraa",
            "phone": "972367087"
        },
        "hasRoles": false,
        "hasRole": false,
        "hasPermissions": false,
        "hasPermission": false,
        "isAdmin": false,
        "isUser": false,
        "isService": false,
        "isCrm": false,
        "isBroker": false,
        "isAgentLicensed": false,
        "isAgentUnlicensed": false
    }
}

Note: For this to work, your application must start its bootstrap as nest-app.

FAQs

Package last updated on 17 Feb 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc