Skip to content

Commit 8a46065

Browse files
authored
add env variable to skip token authentication on endpoints (#72)
1 parent 0ac47a5 commit 8a46065

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ export FIREBASE_PRIVATE_KEY_ID=''
1515
export FIREBASE_PRIVATE_KEY=''
1616
export FIREBASE_CLIENT_EMAIL=''
1717
export FIREBASE_CLIENT_ID=''
18-
export FIREBASE_CLIENT_X509_CERT_URL=''
18+
export FIREBASE_CLIENT_X509_CERT_URL=''
19+
20+
# To skip firebase token authentication on endpoints. DO NOT ENABLE IN PRODUCTION.
21+
export SKIP_FIREBASE_TOKEN_AUTH=false

server/auth.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from .firebase import auth
22
from pydantic import BaseModel
33
from functools import wraps
4-
from typing import Callable, Optional, TypeVar, cast
4+
from typing import Callable, TypeVar, cast
55
from flask import abort, request, jsonify, g
66
from .logging import logger
7+
from .config import SKIP_FIREBASE_TOKEN_AUTH
78

89
class FirebaseIDTokenData(BaseModel):
910
uid: str
@@ -47,6 +48,9 @@ def protected_route():
4748
"""
4849
@wraps(f)
4950
def decorated_function(*args, **kwargs):
51+
if SKIP_FIREBASE_TOKEN_AUTH:
52+
return f(*args, **kwargs)
53+
5054
auth_header = request.headers.get('Authorization')
5155
if not auth_header or not auth_header.startswith('Bearer '):
5256
return jsonify({"error": "Authorization header required"}), 401

server/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import os
22
import logging
3+
from typing import Literal
4+
5+
SKIP_FIREBASE_TOKEN_AUTH = bool(os.getenv("SKIP_FIREBASE_TOKEN_AUTH", False))
36

47
# See if we are running in subnet mode
58
SUBNET_MODE = os.getenv("subnet_mode", "false").lower() == "true"

0 commit comments

Comments
 (0)