cognito-token-validator

Token Validator

A Python package for validating AWS Cognito tokens and using them as decorators. You can use this package with Flask or any other Python framework.

Installation

pip install cognito-token-validator

Usage

Initialization

First, initialize the TokenValidator with the necessary parameters:

from cognito_token_validator import TokenValidator

# Initialize the TokenValidator
token_validator = TokenValidator(
    region='us-east-1',
    user_pool_id='your_user_pool_id',
    client_id='your_client_id',
    get_auth_header=lambda: request.headers.get('Authorization'),
    whitelisted_emails=['example@example.com']
)

Using with Flask

To use the TokenValidator in a Flask app, apply the token_required decorator to your routes:

from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/protected')
@token_validator.token_required
def protected():
    return 'This is a protected route'

if __name__ == '__main__':
    app.run(debug=True)

License

This project is licensed under the MIT License - see the LICENSE file for details.