Skip to content
forked from du2x/jwtlab

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

License

Notifications You must be signed in to change notification settings

gitter-badger/jwtlab

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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":"scott@gmail.com", "password":"12345"}' http://localhost:5000/signin`

  2. access a restricted area

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 44.0%
  • Python 34.4%
  • HTML 21.6%