Code Monkey home page Code Monkey logo

nestjspackagejwtauthenticationldap's Introduction

README

Links

based on

NestJsPackageJwtAuthenticationLdap is a simple nestjs package to easy bootstrap jwt with ldap authentication in nestjs projects. this project have a nestjs-package-jwt-authentication-ldap nestjs package, and package consumer app nestjs-package-jwt-authentication-ldap-consumer, nodemon configured on both package and app, hot reload, vscode debugger on package and on consumer app ready to roll

NOTE: please read notes from above repo links

Required Tooling

# used version on c3 and dev machine both works
$ node -v
v10.19.0
$ node -v
v16.6.2
# require
$ sudo npm install -g @nestjs/cli

Checkout Project

$ git clone https://github.com/koakh/NestJsPackageJwtAuthenticationLdap.git
$ cd NestJsPackageJwtAuthenticationLdap

Start/Build Development Package

# in terminal #1
$ cd nestjs-package-jwt-authentication-ldap
# optional, only if checkout project
$ npm i --legacy-peer-deps
$ npm run start:dev
[10:27:42 AM] Starting compilation in watch mode...
[10:27:48 AM] Found 0 errors. Watching for file changes.
# done running in watch mode

Start Consumer App

# in terminal #2
$ cd nestjs-package-jwt-authentication-ldap-consumer
# optional to use local package remove `"@koakh/nestjs-package-jwt-authentication-ldap": "^1.0.21"` from `package.json`,
# else leave package.json and use latest published version
$ npm i ../nestjs-package-jwt-authentication-ldap/
# optional, only if checkout project
$ npm i
# DEPRECATED
# start in dev or debug (this will debug consumer app)
$ npm run start:dev | debug
# or
$ npm run start:debug

# check `Debugger attached.` in terminal #2

# now launch `Attach to Process` debugger configuration

# or ctrl+c and `Launch Program` debugger configuration
# F5, this will  this will debug package and comsumer app ate same time

to test debugger breakpoint and breakpoint in bellow line const { user: { cn: username, userPrincipalName: email, dn: userId, memberOf } } = req;

@Controller('auth')
@ApiTags('auth')
export class AuthController {
  ...
  async login(
    @Request() req: LoginDto,
    @Response() res,
  ): Promise<LoginResponseDto> {
    // ADD BREAKPOINT HERE
    const { user: { cn: username, userPrincipalName: email, dn: userId, memberOf } } = req;

now launch one request to hit the breakpoint

$ curl --request POST \
  --url https://127.0.0.1/backend/v1/auth/login \
  --header 'content-type: application/json' \
  --header 'user-agent: vscode-restclient' \
  --data '{"username": "student1","password": "1234"}'

Develop both projects

Now develop nestjs package and consumer app with hot reload

Test all endpoints with client.http file

Note: required the awesome REST Client

Create Admin User

$ USER="mario"
$ sudo samba-tool user list
$ sudo samba-tool user create ${USER} password
# test user auth ${​USER}​:root
$ ldapsearch -H ldap://localhost:389 -x -D "cn=${​USER}​,cn=users,dc=c3edu,dc=online" -w "root" -b ou=passport-ldapauth "(uid=${​USER}​)"
# show user
$ sudo samba-tool user show ${​USER}​
$ sudo samba-tool group addmembers "C3Administrator" ${​USER}​
$ sudo samba-tool group listmembers "C3Administrator"

nestjspackagejwtauthenticationldap's People

Contributors

dramos9 avatar koakh avatar snyk-bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.