On my backend, I am trying to extract credentials from the auth_code returned after the I successfully signs in using google on my iphone Simulator using the below code:
credentials = client.credentials_from_clientsecrets_and_code(
CLIENT_SECRET_FILE,
['https://www.googleapis.com/auth/calendar.readonly'],
auth_code,
)
The auth code is obtained fusing GIDSignIn on iOS and passed to my Python FastAPI server to call the code above on it. But I'm constantly getting a request_uri_mismatch
error:
oauth2client.client.FlowExchangeError: redirect_uri_mismatchBad Request
I know client is a deprecated library, but I also tried the newer google-auth libraries and they use Flow and return the same error too.
I've followed and re-checked Google's tutorial here extensively: https://developers.google.com/identity/sign-in/ios/offline-access. I've also referred to the other Stack Overflow answers and extensively checked my enabled redirect urls , but it still does not work for some reason
What does work though is that I tried verifying the ID Token and that works fine and properly returns the email and user properties
verified_info = id_token_verifier.verify_oauth2_token(id_token, requests.Request(), CLIENT_ID)
I use client credentials for iOS and backend credentials and here are my credentials:
After scrolling through dozens of other answers, finally I found a gentleman's suggestion to simply add redirect_uri=''
like so:
credentials = client.credentials_from_clientsecrets_and_code(
CLIENT_SECRET_FILE,
['https://www.googleapis.com/auth/calendar.readonly'],
auth_code,
redirect_uri=""
)