I am facing a problem creating firebase notifications with firebase-admin in django.
After initiating with credentials server responses with code 403. This problem occurs only in production (Ubuntu 22.04, django 3.2.4, firebase-admin 6.5.0), but in my local machine everything works fine.
Which permissions should I use for server account?
This is my code
try:
app = firebase_admin.get_app()
except:
cred = credentials.Certificate('static/service-key.json')
firebase_admin.initialize_app(cred)
try:
if to_user:
db = firestore.client()
doc_ref = db.collection('Users').document(to_user)
doc = doc_ref.get()
if doc.exists:
message = messaging.Message(
notification=messaging.Notification(
title='title',
body='body'
),
data={
'type': 'message'
},
token=doc.to_dict()['token']
)
messaging.send(message)
except Exception as e:
print(e)