项目作者: deejungx

项目描述 :
Flask implementation for Amazon Cognito
高级语言: Python
项目地址: git://github.com/deejungx/flask-cognito-extended.git
创建时间: 2020-11-22T08:25:35Z
项目社区:https://github.com/deejungx/flask-cognito-extended

开源协议:MIT License

下载


Flask-Cognito-Extended

Build Status
codecov
License: MIT

Flask-Cognito-Extended is a Flask implementation of Amazon Cognito. This extension helps quickly implement authentication and authorization solutions based on Amazon’s Cognito. It contains helpful functions and properties to handle token based authentication flows.

  1. pip install Flask-Cognito-Extended

Usage

  1. from flask import Flask, jsonify
  2. from flask_cognito_extended import (
  3. CognitoManager, login_handler,
  4. callback_handler, get_jwt_identity
  5. )
  6. app = Flask(__name__)
  7. # Setup the flask-cognito-extended extention
  8. app.config['COGNITO_SCOPE'] = "aws.cognito.signin.user.admin+email+openid+profile"
  9. app.config['COGNITO_REGION'] = "us-east-1"
  10. app.config['COGNITO_USER_POOL_ID'] = "us-east-1_xxxxxxx"
  11. app.config['COGNITO_CLIENT_ID'] = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
  12. app.config['COGNITO_CLIENT_SECRET'] = "xxxxxxxxxxxxxxxxxxxxxxxxxx" # optional
  13. app.config['COGNITO_DOMAIN'] = "https://yourdomainhere.com"
  14. app.config['COGNITO_REDIRECT_URI'] = "https://yourdomainhere/callback"
  15. cognito = CognitoManager(app)
  16. # Use @login_handler decorator on your login route
  17. @app.route('/login', methods=['GET'])
  18. @login_handler
  19. def login():
  20. return jsonify(msg="User already signed in."), 200
  21. # Use @callback_handler decorator on your callback route
  22. @app.route('/callback', methods=['GET'])
  23. @callback_handler
  24. def callback():
  25. # fetch the unique 'sub' property of the User
  26. current_user = get_jwt_identity()
  27. return jsonify(logged_in_as=current_user), 200
  28. if __name__ == '__main__':
  29. app.run(debug=True)

Development Setup

Using pipenv

  1. pipenv install --dev

Using virtualenv

  1. python3 -m venv env
  2. source env/bin/activate
  3. pip install -r requirements.txt

Contributing

  1. Fork repo- https://github.com/deejungx/flask-cognito-extended/fork
  2. Create your feature branch - git checkout -b feature/foo
  3. Commit your changes - git commit -am "Added foo"
  4. Push to the branch - git push origin feature/foo
  5. Create a new pull request