DEV Community

Budy mnvenom
Budy mnvenom

Posted on • Originally published at blog.icodes.tech

python and firebase auth Sign in anonymously

Visit Python firebase authentication Definitive guide (2021) for more

Sign in anonymously

Sometimes you need to use user's features without creating an account. So you can do it on firebase just by sending another POST request to :

https://identitytoolkit.googleapis.com/v1/accounts:signUp

But You have to enable it first

python firebase enable sign in anonymously

Code :

import requests

apikey='...................'# the web api key

def SignInAnonymously():
    headers = {
        'Content-Type': 'application/json',
    }
    data='{"returnSecureToken":"true"}'
    r = requests.post('https://identitytoolkit.googleapis.com/v1/accounts:signUp?key={}'.format(apikey), headers=headers, data=data)
    if 'error' in r.json().keys():
        return {'status':'error','message':r.json()['error']['message']}
    if 'idToken' in r.json().keys():
        return {'status':'success','idToken':r.json()['idToken']}
Enter fullscreen mode Exit fullscreen mode

Output :

{'status': 'success',
'idToken': 'eyJhbGciOiJSUzI1NiIsImtpZCI6IjkwMDk1YmM2ZGM2ZDY3NzkxZDdkYTFlZWIxYTU1OWEzZDViMmM0'}

Read more Python firebase authentication Definitive guide (2021)

Top comments (0)