Google oauth2 login with python package encountered weird error

Hi all,
I’m using python fastapi as the backend of my mobile app but when I tried to implement google-oauth2 login method with python package it returned a weird message where I can’t find any other posts on the internet with similar issue. The error message reads: a0.sdk.internal.unknown

Any help is appreciated!

Hi @david34,

Welcome to the Auth0 Community!

Hm, I’m not familiar with that error either. Can you provide some more context? Is there a more detailed message? Also, what code is causing this error? Can you share info about which SDK, version, etc.?

Hi Dan,

Thank you for the reply. We using FastAPI (python) as our backend and the frontend will communicate with google and send back the token once they are authorized. We are currently using python auth0 package to handle the social login right now but after passing in the required variable the endpoint will return with the error stated above. did you have any clue where I should start in terms of fixing this error? Thanks!

Yes, please share the SDK name, version, and code you are using.

Hi,
Thanks for the response. We are using auth0-python==3.23.1 and the code we are using is

from auth0.v3.authentication import Social
social = Social(account_url)
social.login(client_id=client_id, access_token=token_returned_by_frontend_signin, connection='google-oauth2')

Are you just trying to validate the token here?

I’m trying to do a social login, but looks like it’s not how it works?

Is your fastapi app functioning as a rest API? Usually you just pass it a bearer token and that grants/forbids access to resources.

yes I understand that. Our frontend is authenticating with google service and that returns a token and we pass that token to auth0 to achieve social login ( registration ) with auth0. we’re just not sure if that’s how it should work.

To confirm, you are authenticating directly with Google in your mobile app, then sending the returned Google Access Token to Auth0?

Are you following a tutorial or doc that is suggesting this flow? I’m a little confused about your setup.

So our frontend app would authenticate with google endpoint and get the token back from google and pass that token into the python sdk. Is that not how we should be doing this? I didn’t really find any documentation on how I should be using the social login feature with the python sdk. Would you mind pointing me to that? Really appreciate it!

Hi! I’m the frontend developer working on the app. We are using Expo’s AuthSession sdk and we’re using it this way:

import { AuthSessionResult } from "expo-auth-session";
import { useAuthRequest } from "expo-auth-session/providers/google";
import { useCallback, useEffect } from "react";
import { StyleProp, ViewStyle } from "react-native";
import { useDispatch } from "../store";
import { googleSignInThunk, getUserThunk } from "../store/actions/userActions";
import { fireHaptics } from "../utils/haptics";
import { Button } from "./Button";

interface Props {
  style?: StyleProp<ViewStyle>;
}

export const GoogleSignInButton = ({ style }: Props) => {
  const dispatch = useDispatch();
  const [request, response, promptAsync] = useAuthRequest({
    expoClientId:
      "455074804612-u81glfa835g8mn47q468j310iofj2iq9.apps.googleusercontent.com",
    webClientId:
      "455074804612-u81glfa835g8mn47q468j310iofj2iq9.apps.googleusercontent.com",
    iosClientId:
      "378340700762-hb92q9qd6v0amp5rf4e90gqceherb493.apps.googleusercontent.com",
    scopes: ["email"],
  });
  const startSignIn = useCallback(async () => {
    try {
      if (!request) return;
      console.log("sign in");
      await promptAsync();
    } catch (e) {
      console.log(e);
      if ((e as { code: string }).code === "ERR_CANCELED") return;
      else {
        // handle other errors
      }
    }
  }, [dispatch, request]);
  const handleSignIn = async (response: AuthSessionResult) => {
    console.log(response);
    if (response.type !== "success") return;
    if (
      (await dispatch(googleSignInThunk(response))).meta.requestStatus ===
      "rejected"
    ) {
      fireHaptics("error");
      return;
    }
    if (
      (await dispatch(getUserThunk(true))).meta.requestStatus === "rejected"
    ) {
      fireHaptics("error");
      return;
    }
  };
  useEffect(() => {
    if (!response) return;
    handleSignIn(response);
  }, [response]);
  return (
    <Button
      style={style}
      onPress={startSignIn}
      title="Google Sign In"
      buttonStyleKey="unfilled"
    />
  );
};

googleSignInThunk basically fires off an api call to our server with what is returned from the response of the user signing in on google.

Hi @MambaEric,

Welcome to the Auth0 Community!

Why aren’t you authenticating with Auth0 in your frontend? You should be able to provide the same UX, but retrieve Auth0 Access Tokens in your front end and start a session. This would be the most common setup.


@david34

I’m actually not familiar with using the SDK like that. This isn’t a flow I’ve seen used before (that is; authenticating directly with the IdP then passing the IdP Access Token to Auth0), but I reach out to the owners of that library and discuss.

Update: I found it, it’s a legacy flow.

https://auth0.com/docs/api/authentication#login15

Since there are several versions of documentation up, what is the correct way a react-native app built with expo and a python background should interface with Auth0? Ideally, the user does not have to go to a webview within the app

@MambaEric,

Have you had the chance to look at our quickstarts that demo the frameworks you listed?

Auth0 offers both options. Have you seen this doc? Add Login to Your Native/Mobile App

I would highly suggest taking a moment to read through our docs before implementing anything. This page is a good place to begin: Get Started