GithubHelp home page GithubHelp logo

studiofu / demo-ng-jwt Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 21 KB

demo of using angular framework with node api backend and JWT auth

TypeScript 63.52% CSS 1.42% HTML 10.13% JavaScript 24.93%

demo-ng-jwt's Introduction

demo of using angular + backend api + jwt auth

This sample is published as part of the corresponding blog article at https://www.toptal.com/angular/angular-6-jwt-authentication.

Visit https://www.toptal.com/blog and subscribe to our newsletter to read great posts!

server

need to add the jwt package

npm install @auth0/angular-jwt

need to install body-parser, jsonwebtoken and express-jwt

npm install body-parser jsonwebtoken express-jwt

  • body-parser is used to analyze, and could process different kind of response type, such as text, json, urlendcoded and could also handle different encoding

sign and create the token

    var token = jwt.sign({userID: user.id}, secretKey, {expiresIn: '2h'});

auth

http://localhost:4000/api/auth/

username and password

Get Todos

http://localhost:4000/api/todos

header: Authorization: Bearer {token}

send the header by using the angular-jwt package and set in the app.modules.ts

    JwtModule.forRoot({
      config: {
        tokenGetter: tokenGetter,
        whitelistedDomains: ['localhost:4000'],
        blacklistedRoutes: ['localhost:4000/api/auth']
      }
    })

and using proxy in ng client to map /api/ to localhost:4000 server proxy.conf.json

logger tutorial

https://www.digitalocean.com/community/tutorials/how-to-use-winston-to-log-node-js-applications

how to refresh token?

send one api token and one refresh token which has longer expiry time than api token

when api token expired and need to use refresh token to get a new api token and also the refresh token

demo-ng-jwt's People

Contributors

codingthat avatar sschocke avatar studiofu 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.