GithubHelp home page GithubHelp logo

iwatakeshi / session-based-authorization-for-nestjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from johnbiundo/mvc-sessions

0.0 1.0 0.0 2.06 MB

Sample code for MVC Sessions article

License: MIT License

TypeScript 97.85% Dockerfile 0.38% Shell 1.77%

session-based-authorization-for-nestjs's Introduction

Session based authorization from Nest.js

This is a code sample for my article

Optional

This example shows how to setup Nest.js authorization various 3rd party providers

  • google
  • facebood
  • onelogin

you have to have them configured in advance only local provider works out of the box

Manual installation

I assume you have node, yarn/npm, postgres, redis

First of all you have to download dependencies

npm i

Then check config in

nano .env

and start in watch mode

npm run start

or in production mode

npm run build
npm run prod

Docker

Otherwise you can use docker

docker-compose up --build

Usage

You can log in to the application using [email protected]/My5up3r5tr0ngP@55w0rd by executing this CURL request

curl -v \
-X POST http://localhost:3000/auth/login \
-d '{"email": "[email protected]", "password": "My5up3r5tr0ngP@55w0rd"}' \
-H "Content-Type: application/json"

Or asymmetric key

curl -v \
-X POST http://localhost:3000/auth/biometric \
-d '{"email": "[email protected]", "signature": "lHBr/oUxp8LYUojNLbTWQ3z3T5Lb2J2fAbgcfyD0PGzlE8Wm3ZQaMyzA3AHgMlHEqnqUKOaRCXGLi6DJkERL2PKDJh3SIWxZujR0gP28rTX+kUJaKAysLRZVqWESXBsnkszSIVYeQH7Y9y9aocGOgye+8HsIgFRz8d5ttF579YUIqs26vhPKLgYiWKUQ4kqAhUhbNQgsuUaBEm9APYDdtb8872mPWX06k52Ig4IAM3dSKi5HGXutY9Ks88Gp69HV0zBHvjrIqHqxF1gUn0GMqDdZQHw/YwVPJAPNo8fPVEpjrasp2pLO5f5g5a2GG/nvDUJPmbuB0TNrcGS4pLwfAA=="}' \
-H "Content-Type: application/json"

Also you can login with provider of your choice on http://localhost:3000/auth/login

This will return your profile

{"id":1,"email":"[email protected]","roles":["admin"]}

This will return a list of users

{"list":[{"id":1,"email":"[email protected]","roles":["admin"]}],"count":1}

Contribution

RPs, especially with new providers, are welcome

session-based-authorization-for-nestjs's People

Contributors

renovate-bot avatar trejgun avatar johnbiundo avatar beeman avatar hegelstad avatar

Watchers

James Cloos 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.