Git Product home page Git Product logo

flask-jwt-auth's Introduction

Flask JWT Auth

Build Status

Want to learn how to build this project?

Check out the blog post.

Want to use this project?

Basics

  1. Fork/Clone
  2. Activate a virtualenv
  3. Install the requirements

Set Environment Variables

Update project/server/config.py, and then run:

$ export APP_SETTINGS="project.server.config.DevelopmentConfig"

or

$ export APP_SETTINGS="project.server.config.ProductionConfig"

Set a SECRET_KEY:

$ export SECRET_KEY="change_me"

Create DB

Create the databases in psql:

$ psql
# create database flask_jwt_auth
# create database flask_jwt_auth_test
# \q

Create the tables and run the migrations:

$ python manage.py create_db
$ python manage.py db init
$ python manage.py db migrate

Run the Application

$ python manage.py runserver

Access the application at the address http://localhost:5000/

Want to specify a different port?

$ python manage.py runserver -h 0.0.0.0 -p 8080

Testing

Without coverage:

$ python manage.py test

With coverage:

$ python manage.py cov

flask-jwt-auth's People

Contributors

d3prof3t avatar mjhea0 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

flask-jwt-auth's Issues

Suggestion for new requirements.txt

Hello, I'd like to thank you for keeping this repository up. This example has given me some ideas for my API.

I'd like to suggest the following requirement versions because the ones in the repo appear to be dated.

alembic==1.4.2
bcrypt==3.1.7
cffi==1.14.0
click==7.1.2
coverage==5.1
Flask==1.1.2
Flask-Bcrypt==0.7.1
Flask-Cors==3.0.8
Flask-Migrate==2.5.3
Flask-Script==2.0.6
Flask-SQLAlchemy==2.4.3
Flask-Testing==0.8.0
itsdangerous==1.1.0
Jinja2==2.11.2
Mako==1.1.3
MarkupSafe==1.1.1
psycopg2==2.8.5
pycparser==2.20
PyJWT==1.7.1
python-dateutil==2.8.1
python-editor==1.0.4
six==1.15.0
SQLAlchemy==1.3.17
Werkzeug==1.0.1

Here is a PR
#23

Thanks again for keeping this example up!

Error while pip install -r requirement.txt

Collecting alembic==0.8.9
Downloading https://files.pythonhosted.org/packages/63/ca/c60ba17274b6737ff9ff1f89f0fbc7da93e05dd12bbdaae5099df8b60d38/alembic-0.8.9.tar.gz (977kB)
|โ–ˆโ– | 40kB 37kB/s eta 0:00:25ERROR: Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/cli/base_command.py", line 153, in _main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/commands/install.py", line 382, in run
resolver.resolve(requirement_set)
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/legacy_resolve.py", line 201, in resolve
self._resolve_one(requirement_set, req)
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/legacy_resolve.py", line 365, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/legacy_resolve.py", line 313, in _get_abstract_dist_for
req, self.session, self.finder, self.require_hashes
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/operations/prepare.py", line 194, in prepare_linked_requirement
progress_bar=self.progress_bar
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/download.py", line 465, in unpack_url
progress_bar=progress_bar
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/download.py", line 316, in unpack_http_url
progress_bar)
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/download.py", line 551, in _download_http_url
_download_url(resp, link, content_file, hashes, progress_bar)
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/download.py", line 253, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/utils/hashes.py", line 80, in check_against_chunks
for chunk in chunks:
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/download.py", line 223, in written_chunks
for chunk in chunks:
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/utils/ui.py", line 160, in iter
for x in it:
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_internal/download.py", line 212, in resp_read
decode_content=False):
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_vendor/urllib3/response.py", line 564, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_vendor/urllib3/response.py", line 529, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 35, in exit
self.gen.throw(type, value, traceback)
File "/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg/pip/_vendor/urllib3/response.py", line 430, in _error_catcher
raise ReadTimeoutError(self._pool, None, "Read timed out.")
ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

Concern with LICENSE

So normally MIT / GPL is applied to a module / plugin. Drop those into your project and it's not derivative works but a dependency, allowing developers to use open source in their projects yet still house IP. This project isn't a module (yet? does using Blueprint portend a module future?). The consequence is clone-and-modify this project, kinda the only way at present, certainly makes a derivative work - meaning our projects are stuck MIT and open. Incidentally I do plan open-sourcing something I'm working on, but AGPL; though I'm sure many plan to use this project as a quickstart boilerplate for closed IP. Any thoughts on this?

Psycopg2 Operational Error: No password supplied

When I try to create the database on applying the migration, I encounter this error:
psycopg2_operational_error

Error

The database URL is set as: postgresql://postgres:@localhost/flask_jwt_auth.

Solve

I managed to change the database URL to now include a password:
postgresql://postgres:postgres@localhost/flask_jwt_auth. postgres is the password for the Postgres database which matches this pattern postgresql://user:password@localhost/database_name.

I think it will be good to include this information in the documentation if anyone encounters such an error.

Reference

https://stackoverflow.com/questions/23839656/sqlalchemy-no-password-supplied-error

import coverage ImportError: No module named coverage

I am getting an error when running :

python manage.py create_db

The error :
Traceback (most recent call last): File "manage.py", line 6, in <module> import coverage ImportError: No module named coverage

I have installed all libraries in requirement.txt via pip install -r requirements.txt

Encode Token test_user_model.py test couldn't pass

Hi, thank you so much for your great tutorial, I just learned "Encode Token", I found that I couldn't pass "test_encode_auth_token" only if I change below code of line 20 self.assertTrue(isinstance(auth_token, bytes)) to self.assertFalse(isinstance(auth_token, bytes)), then they all passed, I don't know the reason why about it. Could you please help me with this issue? Thank you in advance.

Best regards,
Elsa

# project/tests/test_user_model.py

import unittest

from project.server import db
from project.server.models import User
from project.tests.base import BaseTestCase


class TestUserModel(BaseTestCase):

    def test_encode_auth_token(self):
        user = User(
            email='[email protected]',
            password='test'
        )
        db.session.add(user)
        db.session.commit()
        auth_token = user.encode_auth_token(user.id)
        self.assertTrue(isinstance(auth_token, bytes))

if __name__ == '__main__':
    unittest.main() 

'/auth/status' error

auth_token = auth_header.split(" ")[1]
IndexError: list index out of range

auth_header is one piece so splitting it and taking the second part raises "IndexError: list index out of range" error.

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.