Spaces:
Sleeping
Sleeping
updated config
Browse files- src/core/config.py +13 -0
- src/notifications/fcm.py +18 -9
src/core/config.py
CHANGED
|
@@ -46,6 +46,19 @@ class Settings(BaseSettings):
|
|
| 46 |
TOKEN_URL: str = "https://oauth2.googleapis.com/token"
|
| 47 |
GMAIL_SEND_SCOPE: str = "https://www.googleapis.com/auth/gmail.send"
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
@computed_field
|
| 50 |
@property
|
| 51 |
def DATABASE_URL(self) -> PostgresDsn:
|
|
|
|
| 46 |
TOKEN_URL: str = "https://oauth2.googleapis.com/token"
|
| 47 |
GMAIL_SEND_SCOPE: str = "https://www.googleapis.com/auth/gmail.send"
|
| 48 |
|
| 49 |
+
FIREBASE_TYPE: str
|
| 50 |
+
FIREBASE_PROJECT_ID: str
|
| 51 |
+
FIREBASE_PRIVATE_KEY_ID: str
|
| 52 |
+
FIREBASE_PRIVATE_KEY: str
|
| 53 |
+
FIREBASE_CLIENT_EMAIL: str
|
| 54 |
+
FIREBASE_CLIENT_ID: str
|
| 55 |
+
FIREBASE_AUTH_URI: str
|
| 56 |
+
FIREBASE_TOKEN_URI: str
|
| 57 |
+
FIREBASE_AUTH_PROVIDER_X509_CERT_URL: str
|
| 58 |
+
FIREBASE_CLIENT_X509_CERT_URL: str
|
| 59 |
+
FIREBASE_UNIVERSE_DOMAIN: str
|
| 60 |
+
|
| 61 |
+
|
| 62 |
@computed_field
|
| 63 |
@property
|
| 64 |
def DATABASE_URL(self) -> PostgresDsn:
|
src/notifications/fcm.py
CHANGED
|
@@ -1,24 +1,33 @@
|
|
| 1 |
-
import
|
| 2 |
-
import json
|
| 3 |
import httpx
|
| 4 |
from google.oauth2 import service_account
|
| 5 |
import google.auth.transport.requests
|
| 6 |
|
| 7 |
# Your Firebase project ID (from project settings)
|
| 8 |
-
FCM_PROJECT_ID =
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
def get_access_token():
|
| 17 |
"""Generate OAuth2 access token for FCM HTTP v1."""
|
| 18 |
scopes = ["https://www.googleapis.com/auth/firebase.messaging"]
|
| 19 |
|
| 20 |
-
credentials = service_account.Credentials.
|
| 21 |
-
|
| 22 |
)
|
| 23 |
|
| 24 |
request = google.auth.transport.requests.Request()
|
|
|
|
| 1 |
+
from src.core.config import settings
|
|
|
|
| 2 |
import httpx
|
| 3 |
from google.oauth2 import service_account
|
| 4 |
import google.auth.transport.requests
|
| 5 |
|
| 6 |
# Your Firebase project ID (from project settings)
|
| 7 |
+
FCM_PROJECT_ID = settings.FIREBASE_PROJECT_ID # <-- change this
|
| 8 |
|
| 9 |
+
|
| 10 |
+
service_account_info = {
|
| 11 |
+
"type": settings.FIREBASE_TYPE,
|
| 12 |
+
"project_id": settings.FIREBASE_PROJECT_ID,
|
| 13 |
+
"private_key_id": settings.FIREBASE_PRIVATE_KEY_ID,
|
| 14 |
+
"private_key": settings.FIREBASE_PRIVATE_KEY.replace("\\n", "\n"),
|
| 15 |
+
"client_email": settings.FIREBASE_CLIENT_EMAIL,
|
| 16 |
+
"client_id": settings.FIREBASE_CLIENT_ID,
|
| 17 |
+
"auth_uri": settings.FIREBASE_AUTH_URI,
|
| 18 |
+
"token_uri": settings.FIREBASE_TOKEN_URI,
|
| 19 |
+
"auth_provider_x509_cert_url": settings.FIREBASE_AUTH_PROVIDER_X509_CERT_URL,
|
| 20 |
+
"client_x509_cert_url": settings.FIREBASE_CLIENT_X509_CERT_URL,
|
| 21 |
+
"universe_domain": settings.FIREBASE_UNIVERSE_DOMAIN,
|
| 22 |
+
}
|
| 23 |
|
| 24 |
|
| 25 |
def get_access_token():
|
| 26 |
"""Generate OAuth2 access token for FCM HTTP v1."""
|
| 27 |
scopes = ["https://www.googleapis.com/auth/firebase.messaging"]
|
| 28 |
|
| 29 |
+
credentials = service_account.Credentials.from_service_account_info(
|
| 30 |
+
service_account_info, scopes=scopes
|
| 31 |
)
|
| 32 |
|
| 33 |
request = google.auth.transport.requests.Request()
|