{"library":"nsj-flask-auth","title":"Nasajon Flask Authentication","description":"nsj-flask-auth is a basic module designed for authenticating Flask applications within the Nasajon ecosystem. It provides tools for JWT-based authentication, integrating with Flask routes via decorators. Currently at version 0.11.1, its release cadence is tied to internal Nasajon project needs, typically with updates released as new features or fixes are required.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install nsj-flask-auth"],"cli":null},"imports":["from nsj_flask_auth.auth_manager import AuthManager","from nsj_flask_auth.decorator import auth_required"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom flask import Flask, jsonify\nfrom nsj_flask_auth.auth_manager import AuthManager\nfrom nsj_flask_auth.decorator import auth_required\n\napp = Flask(__name__)\n\n# Configure authentication settings\napp.config['NSJ_AUTH_TOKEN_HEADER'] = os.environ.get('NSJ_AUTH_TOKEN_HEADER', 'Authorization')\napp.config['NSJ_AUTH_JWT_SECRET'] = os.environ.get('NSJ_AUTH_JWT_SECRET', 'your-super-secret-key-here')\napp.config['NSJ_AUTH_ALGORITHMS'] = os.environ.get('NSJ_AUTH_ALGORITHMS', 'HS256') # Comma-separated for multiple\n\n# Initialize AuthManager with the Flask app\nauth_manager = AuthManager(app)\n\n@app.route('/')\ndef home():\n    return \"Welcome! This route is public.\"\n\n@app.route('/protected')\n@auth_required\ndef protected_route():\n    # Access current user info after authentication\n    user_info = auth_manager.current_user()\n    return jsonify({\"message\": \"This is a protected route!\", \"user\": user_info.to_dict()})\n\nif __name__ == '__main__':\n    # Example usage: Set environment variables or ensure app.config is properly set\n    # For testing, you might use a tool like Postman to send a JWT token\n    # in the 'Authorization' header: 'Bearer <your_jwt_token>'\n    app.run(debug=True, port=5000)","lang":"python","description":"This quickstart demonstrates how to initialize `nsj-flask-auth` with a Flask application, configure essential settings like the JWT secret and token header, and protect a route using the `@auth_required` decorator. Configuration is pulled from `app.config`, which can be populated via environment variables for security and flexibility. Run this, then access `/protected` with a valid JWT in the Authorization header to test.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}