Search code examples
python-3.xfirebase-authenticationfirebase-admin

Retrieve idToken and refreshToken in Firebase-admin Python SDK


I need to retrieve idToken and refreshToken of a user(firebase_admin._user_mgt.UserRecord object). This is the function I use to create a new user with flask.

@app.route('/user/SignUp')
def user_signup():
    """ Sign up new users """

    email = request.args.get('email')
    password = request.args.get('password')

    try:
        new_user = auth.create_user(
            email=email,
            email_verified=False,
            password=password,
            disabled=False)
        print ("- - - new user created - - - ")


    except Exception as e:
        print ("- - - create_user error : {} - - - ".format(str(e)))
        return jsonify(
            error=str(e),
            status="FAILED"
        )

If we use bellow web API endpoint it responses with both keys https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser

docs : https://firebase.google.com/docs/reference/rest/auth/#section-create-email-password

Is there a way to achieve this without using the web API?

Thanks.


Solution

  • You can't retrieve ID token and refresh token using Admin SDK create_user API. You have to use the client SDKs to do so.