Djai
Djai

Reputation: 196

connect to firebase using API key and application username password

I worked with firebase connectivity from application and from backend server using admin SDK.

Firebase admin SDK used Service account key to connect to firebase backend. Here my use case is: i have a python package which will get used by client, here i do not want to use Service account key and admin SDK. I wanted to use API key and if user enters valid username and password of application (assuming user is already signed up) , user will get access to firebase backend. (Obviously as per security rules)

I am not able to find a method to access firebase backend using API key and applications username/Password from python script. If anyone knows it please help me on this.

Upvotes: 0

Views: 1637

Answers (2)

Frank van Puffelen
Frank van Puffelen

Reputation: 598765

The Admin SDK that Firebase provides for Python is only meant to be used in trusted environments, and doesn't allow signing in with username/password. All code using the Admin SDK is accessing Firebase using administrative privileges, so it is not suitable for your use-case. Firebase itself doesn't provide a SDK for client-side access using Python. So the only option remaining that Firebase provides is to call the REST API from your code.

There is a third party library called Pyrebase that allows you to sign in users (by wrapping the REST API mentioned above):

# Get a reference to the auth service
auth = firebase.auth()

# Log the user in
user = auth.sign_in_with_email_and_password(email, password)

Upvotes: 2

Cl0ud-l3ss
Cl0ud-l3ss

Reputation: 185

IF you want to control the backend access with an API key - you can't.

Unlike how API keys are typically used, API keys for Firebase services are not used to control access to backend resources; that can only be done with Firebase Security Rules (to control which users can access resources) and App Check (to control which apps can access resources).

as per docs

Upvotes: 1

Related Questions