GithubHelp home page GithubHelp logo

clarmy / flask-restful-login Goto Github PK

View Code? Open in Web Editor NEW

This project forked from melihcolpan/flask-restful-login

0.0 0.0 0.0 100 KB

Flask restful service consists of register, login, logout, reset password and some data routes. It includes a few example routes based on user, admin, or super admin access.

License: MIT License

Python 100.00%

flask-restful-login's Introduction

flask-restful-login-example

Build Status

INSTALLATION

  • Python 3 is required. There are ways to send requests to server.
  • Postman, Insomnia, cURL, httpie and curl are simple and useful tools to send requests.
  • I mostly prefer httpie and curl. Their usage can be seen below.

Pull project and install requirements to virtual environment (https://pypi.org/project/virtualenv/). Then run.

$ git clone https://github.com/melihcolpan/flask-restful-login
$ cd flask-restful-login
$ virtualenv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ python -m main

Example user, admin and super admin users are created in database initializer class. You can use these users to login, logout and data handlers. For register handler, use new user information, otherwise returns already exist user.

Test Users Email Address Password
User [email protected] test_password
Admin [email protected] admin_password
Super Admin [email protected] sa_password

Register:

  • HTTPIE Request:
http POST :5000/v1/auth/register username=example_username password=example_password [email protected]
  • Curl Request:
curl -H "Content-Type: application/json" --data '{"username":"example_name","password":"example_password", "email":"[email protected]"}' http://localhost:5000/v1/auth/register

Login:

  • HTTPIE Request:
http POST :5000/v1/auth/login [email protected] password=example_password
  • Curl Request:
curl -H "Content-Type: application/json" --data '{"email":"[email protected]", "password":"example_password"}' http://localhost:5000/v1/auth/login

Response: Got access token and refresh token!

Logout:

  • HTTPIE Request:
http POST :5000/v1/auth/logout Authorization:"Bearer ACCESS_TOKEN" refresh_token=REFRESH_TOKEN
  • Curl Request:
curl -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" --data '{"refresh_token":"REFRESH_TOKEN"}' http://localhost:5000/v1/auth/logout

Reset Password:

  • HTTPIE Request:
http POST :5000/v1/auth/password_reset Authorization:"Bearer ACCESS_TOKEN" old_pass=<OLD-PASSWORD> new_pass=<NEW-PASSWORD>
  • Curl Request:
curl -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" --data '{"old_pass":"OLD-PASSWORD", "new_pass":"NEW-PASSWORD"}' http://localhost:5000/v1/auth/password_reset

There are some example routes in UserHandlers file. These handlers mostly return only text. To use them:

Example routes that require authentication

Route addresses according to user privileges

User Type Route Address
User /data_user
Admin /data_admin
Super Admin /data_super_admin
  • HTTPIE Request:
http GET :5000/<ROUTE-ADDRESS> Authorization:"Bearer ACCESS_TOKEN"
  • Curl Request:
curl -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" http://localhost:5000/<ROUTE-ADDRESS>

Super admin requiring authentication extra example handler, list users

This handler searches username, email or creation dates (range) in users table and returns information these users to super admin.

  • HTTPIE Request:
http GET :5000/users Authorization:"Bearer ACCESS_TOKEN" usernames==test_username,admin_username [email protected],[email protected] start_date==01.01.1990 end_date==01.01.2050
  • Curl Request:
curl -X GET 'localhost:5000/users?usernames=test_username,admin_username&[email protected],[email protected]&start_date=01.01.1990&end_date=01.01.2050' -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" 

License

MIT

Free Software, Hell Yeah!

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.