Code Monkey home page Code Monkey logo

flask-restful-role-auth's Introduction

#基于Token及用户权限的Flask-Restful的Example

  1. 以Token为认证
  2. 拥有用户角色权限管理

#主要组成

  1. Flask
  2. Flask-Restful
  3. Flask-SQlAlchemy
  4. Flask-Security

#其他可选方案

  1. Flask-JWT & Flask-Principal
  2. itsdangerous & Flask-Principal
  3. Flask-Login & Flask-Principal
  4. ...

#运行

pip install -r ./requirement.txt
python manage.py

#测试

$ curl -X POST -H "Content-Type:application/json" -d '{"username":"test1","password":"test1"}' http://localhost:5000/login
{
    "message": "登录成功",
    "token": "WyIxIiwiOThiZmVlMjFlZjljYTU0NzZkYzNmMTUyODUzNDM2MzgiXQ.CgpV7Q.ypduIJefgJAdHAbB_WIrLzfsXYc"
}
$ curl -H "Content-Type:application/json" -H "Authorization: WyIxIiwiOThiZmVlMjFlZjljYTU0NzZkYzNmMTUyODUzNDM2MzgiXQ.CgpV7Q.ypduIJefgJAdHAbB_WIrLzfsXYc" "http://localhost:5000/protected"
{
    "msg": "这是需要Token的GET方法"
}
$ curl -X POST -H "Authorization: WyIxIiwiOThiZmVlMjFlZjljYTU0NzZkYzNmMTUyODUzNDM2MzgiXQ.CgpV7Q.ypduIJefgJAdHAbB_WIrLzfsXYc" "http://localhost:5000/protected"
{
    "msg": "这是需要Token和admin权限的POST方法"
}

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.