nhorvath / Pyrebase4

A simple python wrapper for the Firebase API. ⛺
258 stars 64 forks source link

FB ve Google Login #56

Open mthnzbk opened 1 year ago

mthnzbk commented 1 year ago

Will the methods for logging in with facebook-google be added?

AsifArmanRahman commented 1 year ago

@mthnzbk in case you need those methods for a project, check firebase-rest-api where I've already implemented them.

mthnzbk commented 1 year ago

`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\auth__init__.py", line 78, in authenticate_login_with_facebook return self.create_authentication_uri('facebook.com') File "C:\Users\venv\lib\site-packages\firebase\auth__init__.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" }

AsifArmanRahman commented 1 year ago

@mthnzbk please report the issue in firebase-rest-api repository.

absolutelyspoton commented 1 year ago

I implemented the method sign_in_with_idp_token for the Auth class, which works nicely ; be good to see this added into the main branch.

def sign_in_with_idp_token(self, token, redirect_uri, provider):
    request_ref = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key={0}".format(self.api_key)
    headers = {"content-type": "application/json; charset=UTF-8"}
    postbody = "id_token=" + token + "&providerId=" + provider
    data = json.dumps({"postBody":postbody,"requestUri":redirect_uri,"returnIdpCredential":True,"returnSecureToken":True})
    request_object = requests.post(request_ref, headers=headers, data=data)
    raise_detailed_error(request_object)
    return request_object.json()

Params ( token = id_token (oauth token given back from the provider), redirect_uri e.g. "https://localhost", and provider is the identify platform provider e.g. "google.com" for google signin. Tested for Google, but should work with other providers ok.