Giter VIP home page Giter VIP logo

jwtlab's Introduction

JWTLAB

This is a simple example of JWT usage for authentication with python on server side and angularjs on client side.

What is JWT?

JWT (JSON Web Token) is compact and self-contained way for securely transmitting information between parties as a JSON object defined on a RFC (#7519).

The main usage for JWT may be for authentication/authorization purposes but it can be used also for exchanging information between parties.

What does JWTLAB do?

It runs a webserver (Flask) on localhost, port 5000, exposing the following routes:

  1. /: renders index.html, a html page that links to all other routes.
  2. /signin: receives a login/password combinades and validates it. If it's correct, the response will contain an authentication token.
  3. /public: a simple endpoint that doesn't demand a valid token.
  4. /restricted: a simple endpoint that demands a valid token.

These routes are all implemented in server.py. Furthermore, there are an AngularJS client, implemented in /static/app.js.

How to run JWTLAB?

  1. install requirements pip install -r requirements.txt
  2. run the Flask app python server.py
  3. access http://localhost:5000 with your browser.
  4. to login use any of the credentials in users.json.

How to test it?

You can test it surfing with your browser or using curl in your bash:

  1. authenticate and store token

    token=`curl -H "Content-Type: application/json" -X POST -d '{"email":"[email protected]", "password":"12345"}' http://localhost:5000/signin`

  2. access a restricted area

    curl -X GET http://localhost:5000/restricted -H "Authorization: Bearer $token"

jwtlab's People

Contributors

du2x avatar

Watchers

 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.