Skip to main content

Provide route decorators for Google App Engine users

Project description

Flask Google App Engine Users

Provide route decorators for Google App Engine users.

Author

Daniel 'Vector' Kerr (vector@vector.id.au)

License

Refer to LICENSE.txt.

Installation

pip install flask-gae-users

Sample Usage

Python Code

main.py

from flask import Flask, request, Response, jsonify
from flask_gae_users import GAEUsers
from flask_gae_users import GAENoUserException
from flask_gae_users import GAENotAdminException


app = Flask()
GAEUsers( app = app )

# Provide a response when a user is not logged in
@app.errorhandler( GAENoUserException )
def onAppNoUser( e ):
  body = "<p>You must log in to continue</p>"
  body = body + "<p><a href=\"" + app.get_login_url() + "\">Sign in</a></p>"
  return Response( body, status = 401 )

# Provide a response when a user is not an administrator
@app.errorhandler( GAENotAdminException )
def onAppNoUser( e ):
  body = "<p>You are not authorized to access this resource</p>"
  body = body + "<p><a href=\"" + app.get_logout_url() + "\">Sign in as a different user</a></p>"
  return Response( body, status = 403 )


# Create a user-protected route by adding the `require_user` decorator
@app.route( '/home', methods = [ 'GET' ] )
@app.require_user()
def routeHome():
  user = app.get_user()
  return jsonify( { 'user': repr( user ) } )

# Create an admin-protected route by adding the `require_admin` decorator
@app.route( '/admin', methods = [ 'GET' ] )
@app.require_admin()
def routeAdmin():
  admin = app.get_user()
  return jsonify( { 'admin': repr( admin ) } )


# Run the flask application
if __name__ == '__main__':
  app.run( port = 8080 )

Run Server

python main.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask-gae-users-0.0.1.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

flask_gae_users-0.0.1-py2-none-any.whl (2.9 kB view details)

Uploaded Python 2

File details

Details for the file flask-gae-users-0.0.1.tar.gz.

File metadata

File hashes

Hashes for flask-gae-users-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2938e141b1b4e84119a6b99b02aada9a342ffaf9dbfc89606851193b2f48b711
MD5 0cf9337d56689f839a5ab6088c8cdb3b
BLAKE2b-256 981653b111ff5461f88fa3ed7848034f3b03efe7e316a838d78c77ed63a06f6e

See more details on using hashes here.

File details

Details for the file flask_gae_users-0.0.1-py2-none-any.whl.

File metadata

File hashes

Hashes for flask_gae_users-0.0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 2248b55d74cbd7746be58e9d33159a9b5a214c69614bac8318630dfccec0fd18
MD5 985925f3d7bedebf4fac876ddb6ff5f8
BLAKE2b-256 9c350ce794a96f2c68e9550198c57aeac11f71bc79f591bf31abe701e00c0736

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page