Authenticate users with AWS Cognito
Project description
AWS Cognito for authentication in Flask
Documentation https://flask-awscognito.readthedocs.io
Example App
from flask import Flask, redirect, request, jsonify
from flask_awscognito import AWSCognitoAuthentication
app = Flask(__name__)
app.config['AWS_DEFAULT_REGION'] = 'eu-west-1'
app.config['AWS_COGNITO_DOMAIN'] = 'domain.com'
app.config['AWS_COGNITO_USER_POOL_ID'] = 'eu-west-1_XXX'
app.config['AWS_COGNITO_USER_POOL_CLIENT_ID'] = 'YYY'
app.config['AWS_COGNITO_USER_POOL_CLIENT_SECRET'] = 'ZZZZ'
app.config['AWS_COGNITO_REDIRECT_URL'] = 'http://localhost:5000/aws_cognito_redirect'
aws_auth = AWSCognitoAuthentication(app)
@app.route('/')
@aws_auth.authentication_required
def index():
claims = aws_auth.claims # also available through g.cognito_claims
return jsonify({'claims': claims})
@app.route('/aws_cognito_redirect')
def aws_cognito_redirect():
access_token = aws_auth.get_access_token(request.args)
return jsonify({'access_token': access_token})
@app.route('/sign_in')
def sign_in():
return redirect(aws_auth.get_sign_in_url())
if __name__ == '__main__':
app.run(debug=True)
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-AWSCognito-1.3.tar.gz
(537.5 kB
view hashes)
Built Distribution
Close
Hashes for Flask_AWSCognito-1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb031758b65ae062e0dc7867cf8689f24ea1477a3a48f7e274b0dbee7b829f82 |
|
MD5 | 86d338d7dd5715f3b11291d6ac2d5f62 |
|
BLAKE2b-256 | 5b979e9e105e79ec74b237cbb2fb26d1fd62e10f489677d99e68269d98d3d991 |