Saurav
Saurav

Reputation: 1

Issue with redirect URI mismatch for Google OAuth 2.0

I am creating a Python script to generate a token from the user and store the generated token. While testing locally, everything worked fine when I used http://localhost:8000/ as the redirect URI in the Google Console. Here's the flow I used:

# OAuth flow for Gmail
flow = InstalledAppFlow.from_client_secrets_file('Gmail Extraction/client_secret.json', SCOPES)
creds = flow.run_local_server(port=8000, access_type='offline', prompt='consent')
return creds

Now, as part of the next step, I am trying to replicate the actual server. Since I don't have access to a production server yet, I created a GitHub Pages site and updated the redirect URI in the client secret accordingly. However, I am encountering the following error:

then I am getting this error

Error 400: redirect_uri_mismatch You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy. If you're the app developer, register the redirect URI in the Google Cloud Console. Request details: redirect_uri=http://localhost:8000/ flowName=GeneralOAuthFlow

I suspect the issue is related to the port=8000 setting. I also tried explicitly specifying the redirect URI as follows:

creds = flow.run_local_server(port=8000, redirect_uri=redirect_uri_here, access_type='offline', prompt='consent')

Could someone help clarify what needs to be adjusted? I am open to suggestions and options for deploying this in production.

Upvotes: 0

Views: 37

Answers (0)

Related Questions