Skip to content

Commit

Permalink
Merge pull request #41 from swistakm/feature/authentication-backend
Browse files Browse the repository at this point in the history
Feature/authentication backend
  • Loading branch information
swistakm authored Mar 27, 2017
2 parents c476d5f + 94079aa commit a4f269c
Show file tree
Hide file tree
Showing 11 changed files with 1,571 additions and 17 deletions.
28 changes: 16 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
language: python

python:
- 3.5
python: 3.6

install: pip install tox
env:
# falcon 0.3.x test matrix
- TOX_ENV=py33-falcon0.3
- TOX_ENV=py34-falcon0.3
- TOX_ENV=py35-falcon0.3

# falcon 1.0.x test matrix
- TOX_ENV=py33-falcon1.0
- TOX_ENV=py34-falcon1.0
- TOX_ENV=py35-falcon1.0

env:
# linters and coverage
- TOX_ENV=pep8
- TOX_ENV=coverage
- TOX_ENV=pep257

matrix:
include:
- python: 3.6
env: TOX_ENV=py36-falcon0.3,py36-falcon1.0,py36-falcon1.1

- python: 3.5
env: TOX_ENV=py35-falcon0.3,py35-falcon1.0,py35-falcon1.1

- python: 3.4
env: TOX_ENV=py34-falcon0.3,py34-falcon1.0,py34-falcon1.1

- python: 3.3
env: TOX_ENV=py33-falcon0.3,py33-falcon1.0,py33-falcon1.1

script:
- tox -e $TOX_ENV

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ Features:

* generic classes for list and single object resources
* simple but extendable pagination
* simple but extendable authentication and authorization
* structured responses with content/meta separation
* declarative fields and parameters
* self-descriptive-everything: API description accessible both in python and
through `OPTIONS` requests
* painless validation
* 100% tests coverage
* falcon>=0.3.0 (tested up to 1.0.x)
* python3 exclusive (tested from 3.3 to 3.5)
* falcon>=0.3.0 (tested up to 1.1.x)
* python3 exclusive (tested from 3.3 to 3.6)

Community behind graceful is starting to grow but we don't have any mailing
list yet. There was one on [Librelist](http://librelist.com/browser/graceful)
Expand Down
39 changes: 39 additions & 0 deletions demo/auth_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import hashlib

from redis import StrictRedis as Redis
import falcon

from graceful.resources.generic import Resource
from graceful.authentication import KeyValueUserStorage, Token, Basic
from graceful.authorization import authentication_required


@authentication_required
class Me(Resource, with_context=True):
def retrieve(self, params, meta, context):
return context.get('user')


auth_storage = KeyValueUserStorage(Redis())


@auth_storage.hash_identifier.register(Basic)
def _basic(identified_with, identifier):
return ":".join((
identifier[0],
hashlib.sha1(identifier[1].encode()).hexdigest()
))


@auth_storage.hash_identifier.register(Token)
def _token(identified_with, identifier):
return hashlib.sha1(identifier[1].encode()).hexdigest()

api = application = falcon.API(
middleware=[
Token(auth_storage),
Basic(auth_storage),
]
)

api.add_route('/me/', Me())
Loading

0 comments on commit a4f269c

Please sign in to comment.