Skip to content

Commit

Permalink
Create app module in api package with Flask config
Browse files Browse the repository at this point in the history
  • Loading branch information
campb303 committed Jun 16, 2021
1 parent b452e15 commit cae26be
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/webqueue2api/api/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from flask import Flask
from flask_restful import Api
from flask_jwt_extended import JWTManager
from .config import config

app = Flask(__name__)
api = Api(app)

# Set JWT secret key and create JWT manager
app.config["JWT_SECRET_KEY"] = config.jwt_secret_key
# The JWT RFC uses the "sub" key for identity claims. However,
# Flask-JWT-Extended uses "identity" by default for compatibility reasons so
# we ovverride the default claim key to comply with the RFC
app.config["JWT_IDENTITY_CLAIM"] = "sub"
# Set the key for error messages generated by Flask-JWT-Extended
app.config["JWT_ERROR_MESSAGE_KEY"] = "message"

# Look for JWTs in headers (for access) then cookies (for refresh)
app.config["JWT_TOKEN_LOCATION"] = ["headers", "cookies"]
# Restrict cookies to HTTPS in prod, allow HTTP in dev
app.config["JWT_COOKIE_SECURE"] = False if config.jwt_secret_key == "dev" else True
# Restrict cookies using SameSite=strict flag
app.config["JWT_COOKIE_SAMESITE"] = "strict"
# Restrict refresh tokens to /token/refresh endpoint
app.config["JWT_REFRESH_COOKIE_PATH"] = '/tokens/refresh'
# Set the cookie key for CRSF validation string
# This is the default value. Adding it for easy reference
app.config["JWT_REFRESH_CSRF_HEADER_NAME"] = "X-CSRF-TOKEN"

tokenManager = JWTManager(app)

0 comments on commit cae26be

Please sign in to comment.