AsifArmanRahman / firebase-rest-api

A simple python wrapper for Google's Firebase REST API's.
https://firebase-rest-api.readthedocs.io
MIT License
60 stars 14 forks source link

[Bug]: Facebook and Google Login #6

Open mthnzbk opened 1 year ago

mthnzbk commented 1 year ago

Is there an existing issue for this?

Environment

-   OS: W11
-   Python:3.10

What happened?

`Traceback (most recent call last): File "C:\Users\venv\lib\site-packages\firebase_exception.py", line 13, in raise_detailed_error request_object.raise_for_status() File "C:\Users\venv\lib\site-packages\requests\models.py", line 1021, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://www.googleapis.com/identitytoolkit/v3/relyingparty/createAuthUri?key=AIzaSyDFP8PMnJzIl-4q8fsnkz1uvEPE3nHivcA

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\main.py", line 34, in print(auth.authenticate_login_with_facebook()) File "C:\Users\venv\lib\site-packages\firebase\authinit.py", line 78, in authenticate_login_with_facebook return self.create_authentication_uri('facebook.com') File "C:\Users\venv\lib\site-packages\firebase\authinit.py", line 127, in create_authentication_uri raise_detailed_error(request_object) File "C:\User\venv\lib\site-packages\firebase_exception.py", line 17, in raise_detailed_error raise HTTPError(e, request_object.text) requests.exceptions.HTTPError: [Errno 400 Client Error: Bad Request for url: https://www.googleapis.com/identitytoolkit/v3/relyingparty/createAuthUri?key=AIzaSyDFP8PMnJzIl-4q8fsnkz1uvEPE3nHivcA] { "error": { "code": 400, "message": "INVALID_CONTINUE_URI", "errors": [ { "message": "INVALID_CONTINUE_URI", "domain": "global", "reason": "invalid" } ] } }`

I think I entered the information correctly. this is the error I get. auth = firebase.auth(client_secret="client_secret.json") auth.authenticate_login_with_facebook() client_secret.json: { "client_id": "1234", "client_secret": "1a2s", "redirect_uris": "https://xxx.firebaseapp.com/__/auth/handler" }

Code Snippet

import firebase

config = {
    "apiKey": "-",
    "authDomain": ".firebaseapp.com",
    "databaseURL": "https://.europe-west1.firebasedatabase.app",
    "projectId": "",
    "storageBucket": ".appspot.com",
    "messagingSenderId": "",
    "appId": "1::android:",
    "serviceAccount": "firebase.json"
}

firebase = firebase.initialize_app(config)
auth = firebase.auth(client_secret="client_secret.json")
print(auth.authenticate_login_with_facebook())

Relevant log output

No response

Anything else?

No response

github-actions[bot] commented 1 year ago

Hello @mthnzbk , thank you for submitting an issue! A project committer will shortly review the issue.

AsifArmanRahman commented 1 year ago

The key redirect_uris in the client secret file is supposed be an array, not a string.

Please try reformatting it in the following example:

{ 
    "client_id": "1234", 
    "client_secret": "1a2s",
    "redirect_uris": ["https://xxx.firebaseapp.com/__/auth/handler"]
}
mthnzbk commented 1 year ago

"Unable to process request due to missing initial state. This may happen if browser sessionStorage is inaccessible or accidentally cleared." -> When I click on the link and authorize, the firebase link gives this output.

AsifArmanRahman commented 1 year ago
  1. Did you add the redirect uri to the list of authorized redirect URIs for your OAuth app? If you didn't, please do that.
  2. Try opening the link with a different browser.
  3. Also, there is an ongoing issue opened in firebase-js-sdk facing the same issue. I guess the default callback URL has some issue. Could you try using an own built callback URL?
Lxstr commented 1 year ago

Would like your thoughts on including this in the auth docs as it can be a bit confusing when you realise client secret is both the object and within the object. I have remove references to config.py (ie BaseConfig.CLIENT_SECRET), if that is more general.

Client secret as a json file or dict must be passed when using SSO (just google) functions.

auth = app.auth(client_secret=CLIENT_SECRET)

CLIENT_SECRET = {"web": { 
                "client_id": environ.get("CLIENT_ID"), 
                "client_secret": environ.get("CLIENT_SECRET"),
                "redirect_uris": [environ.get("REDIRECT_URI")]
            }}

or

auth = firebase.auth(client_secret="client_secret.json")

client_secret.json format:

{ 
    "client_id": "1234", 
    "client_secret": "1a2s",
    "redirect_uris": ["https://xxx.firebaseapp.com/__/auth/handler"]
}
kengoon commented 1 year ago

please where can i get this client_secret.json

AsifArmanRahman commented 1 year ago

@kengoon Create an API key

AlexJrDevs commented 2 months ago

Where do you get the redirect_uris, I can see one in OAuth but doesn't work. Also my redirect_uris look like http://localhost not like the one you've mentioned. Can someone help me out?

AlexJrDevs commented 2 months ago

Where do you get the redirect_uris, I can see one in OAuth but doesn't work. Also my redirect_uris look like http://localhost not like the one you've mentioned. Can someone help me out?

As soon as I post this I figured it out, sorry. You have to go to your authentication settings in firebase and click authorized domains, find the link which ends in .com and paste it: https://paste_here/__/auth/handler After this, I'm unsure how to get rid of as I added the redirect uri to the authorized apps in google cloud.

"Unable to process request due to missing initial state. This may happen if browser sessionStorage is inaccessible or accidentally cleared. Some specific scenarios are - 1) Using IDP-Initiated SAML SSO. 2) Using signInWithRedirect in a storage-partitioned browser environment."