Git Product home page Git Product logo

flask-praetorian's Introduction

Latest Published Version Build Status Documentation Build Status

flask-praetorian

Strong, Simple, and Precise security for Flask APIs

API security should be strong, simple, and precise like a Roman Legionary. This package aims to provide that. Using JWT tokens as implemented by PyJWT, flask_praetorian uses a very simple interface to make sure that the users accessing your API's endpoints are provisioned with the correct roles for access.

This project was heavily influenced by Flask-Security, but intends to supply only essential functionality. Instead of trying to anticipate the needs of all users, flask-praetorian will provide a simple and secure mechanism to provide security for APIs specifically.

This extension offers a batteries-included approach to security for your API. For essential security concerns for Flask-based APIs, flask-praetorian should supply everything you need.

The flask-praetorian package can be used to:

  • Hash passwords for storing in your database
  • Verify plaintext passwords against the hashed, stored versions
  • Generate authorization tokens upon verification of passwords
  • Check requests to secured endpoints for authorized tokens
  • Supply expiration of tokens and mechanisms for refreshing them
  • Ensure that the users associated with tokens have necessary roles for access
  • Parse user information from request headers for use in client route handlers
  • Support inclusion of custom user claims in tokens
  • Register new users using email verification

All of this is provided in a very simple to configure and initialize flask extension. Though simple, the security provided by flask-praetorian is strong due to the usage of the proven security technology of JWT and python's PassLib package.

Super-quick Start

  • requirements: python versions 3.8+
  • install through pip: $ pip install flask-praetorian
  • minimal usage example: example/basic.py

Documentation

The complete documentation can be found at the flask-praetorian home page

flask-praetorian's People

Contributors

archtaurus avatar brsntus avatar christofer-f avatar dependabot[bot] avatar dmitryint avatar dusktreader avatar erikmmkarlsson avatar imoyao avatar jvllmr avatar klucsik avatar lakotelman avatar lawrencealexander10 avatar timgates42 avatar uwu-ara avatar valuesize avatar vpassapera avatar zyeri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-praetorian's Issues

Fix flake8 error

$ flake8 tests
tests/conftest.py:27:9: E722 do not use bare except'

Figure out how to register /auth endpoint with swagger

Figure out what needs to be done so that the /auth endpoint inherited from flask_jwt is available to swagger for projects that use it to automatically document their api. Make sure that the swagger documentation includes some good explanation of how the endpoint works

Rearrange docs a little bit

  • Make the link from README to the document pages more samless
  • Drop the links to the raw sphinx docs
  • Update badges in README
  • Fix conf.py inclusion of base package
  • Fixup setup.py while at it
  • Add classifiers to setup.py

Switch back to bcrpyt as the default

Turns out that argon2 has a dependency in Ubuntu for libffi-dev. Installing via pip will not resolve this dependency.

Try adding cffi as an explicit install requirement or some of the other approaches mentioned here:
Kozea/cairocffi#14

If there is not a solution that resolves all dependencies without having to install anything but python and pip on the system, switch the default back to bcrypt

Update README

  • Add build-status image
  • Replace 'included' text with...sigh...copy

Fix issue with eternal tokens and setting the JWT_*_LIFESPAN variables

Eternal tokens don't work because the value of the max interval is too great to add to the current time. So just use a very large interval instead of the maximum one.

Also, there isn't an easy way to parse a string to an Interval. So, instead of having the JWT_*_LIFESPAN variables expect to be an Interval, instead make them a dict that can be used to create an interval

Add argon2 support

When passlib1.7 is released, add argon2 support so that it may be used as the encryption scheme. It should also become the default at that point.

fix warnings

When running the test suite, the following warnings come up:

  pytest-capturelog plugin has been merged into the core, please remove it from your requirements.

tests/test_base.py::TestPraetorian::()::test_encrypt_password
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py:794: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
    'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '

tests/test_base.py::TestPraetorian::()::test_validate_jwt_data
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)

tests/test_base.py::TestPraetorian::()::test_encode_jwt_token
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)

tests/test_base.py::TestPraetorian::()::test_encode_eternal_jwt_token
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)

tests/test_base.py::TestPraetorian::()::test_refresh_jwt_token
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)

tests/test_base.py::TestPraetorian::()::test_read_token_from_header
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)

tests/test_base.py::TestPraetorian::()::test_pack_header_for_user
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)

tests/test_decorators.py::TestPraetorianDecorators::()::test_auth_required
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/work/flask-praetorian/tests/test_decorators.py:77: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    default_guard.access_lifespan
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2064: PendulumDeprecationWarning: The subtract_timedelta() method will be removed in version 2.0.
    return self.subtract_timedelta(other)
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)

tests/test_decorators.py::TestPraetorianDecorators::()::test_roles_required
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)

tests/test_decorators.py::TestPraetorianDecorators::()::test_roles_accepted
  /Users/tbeck/.virtualenvs/praetorian/lib/python3.6/site-packages/pendulum/pendulum.py:2081: PendulumDeprecationWarning: The add_timedelta() method will be removed in version 2.0.
    return self.add_timedelta(other)

-- Docs: http://doc.pytest.org/en/latest/warnings.html

Add verify_and_update support

We will need the ability to verify a password using it's encryption algorithm and then re-encrypt with a new algorithm. This is necessary if an application decides to switch encryption methods but still needs current passwords to function correctly.

Add a call to optional user method 'validate'

It should be possible for the User class used by the client code to have a validate method. This method could be used to make sure that a user is still active, hasn't changed username, etc.

The method should raise an exception if it fails

Quickstart Typo

Hello, I'm going through the quickstart guide for the first time to give flask-praetorian a try. In the quickstart,

POST /auth HTTP/1.1
Host: localhost:5000
Content-Type: application/json
{
    "username": "TheDude",
    "password": "abides"
}

should be

POST /login

for the current example as it does not have /auth endpoint. The docs should also reflect that.

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.