Skip to content

Commit

Permalink
fix update docs formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bret.ikehara committed May 20, 2016
1 parent 884a887 commit 47a35e8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions README.rst
Expand Up @@ -47,48 +47,56 @@ If access is granted, the authentication module exposes roles and token's claims


Securing custom routes
-------------
----------------------

JWT Authorization can be applied to any custom routes using the `@requires_token` wrapper. This annotation will only provide *audience and role access control*. User level access must be written manually.

Example of audience access control::

from eve_auth_jwt import requires_token, get_request_auth_value

@app.route('/my_resource/download', methods=['GET'])
@requires_token(audiences=['myAudience'])
def csv_download():
# Allows all users with myAudience to access download
account_id = get_request_auth_value()

if check_user(account_id):

abort(401)

return generateCSV(account_id)

Here is an example of `myAdmin` access control:
Example of `myAdmin` access control::

from eve_auth_jwt import requires_token

@app.route('/admin/my_resource/download', methods=['GET'])
@requires_token(audiences=['myAudience'], allowed_roles=['myAdmin'])
def csv_download():
account_id = request.args.get('account_id', None)

return generateCSV(account_id)


Access the parsed JWT token values
-------------
----------------------------------

The parsed JWT token values are stored in the `flask.g` dict, but custom functions exist to aid in reading the values. The values are only available after the JWT token integrity check and user authorization occurs.

from eve_auth_jwt import get_request_auth_value, get_authen_claims, get_authen_roles
Example of access the parse JWT token fields::

from eve_auth_jwt import get_request_auth_value, get_authen_claims, get_authen_roles

def my_fn():
# Request authentication value as a str
account_id = get_request_auth_value()

# JWT claims as a dict[str]
payload = get_authen_claims()

# Roles as arr[str]
roles = get_authen_roles()


Licenses
--------

Expand Down

0 comments on commit 47a35e8

Please sign in to comment.