11

I'm getting this error while trying to run my application...

The redirect URI in the request: http://localhost:8080/oauth2callback did not match a registered redirect URI

In google API console i have registered my redirect urls

Redirect URIs:  http://localhost:8080/

And in the client_secrets.json also i'm using the same as redirect url I'm following this tutorial https://developers.google.com/bigquery/articles/dashboard#addoauth2

Edit:

I just made some changes to the existing code

Now the

redirect URIs in API console is     http://localhost:8080/oauth2callback

And here is my app.yaml

application: hellomydashboard
version: 1
runtime: python
api_version: 1

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /oauth2callback
  script: oauth2client/appengine.py

- url: .*
  script: main.py

Now though its not showing any error but it displays a blank page.

Here is my main.py

from bqclient import BigQueryClient
import httplib2
import os
from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from oauth2client.appengine import oauth2decorator_from_clientsecrets

# Project ID for project to receive bill.
# During limited availability preview, there is no bill.
# The value should be your quoted Client ID number 
# which you previously recorded from code.google.com/apis/console

# REPLACE THIS NUMBER WITH YOUR CLIENT ID
PROJECT_ID = "My Project ID"  #i just replaced dat
DATASET = "samples"
TABLE = "natality"

# CLIENT_SECRETS, name of a file containing the OAuth 2.0
# information for this application.
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__),
    'client_secrets.json')

http = httplib2.Http(memcache)
decorator = oauth2decorator_from_clientsecrets(CLIENT_SECRETS,
    'https://www.googleapis.com/auth/bigquery')

bq = BigQueryClient(http, decorator)

class MainHandler(webapp.RequestHandler):
    @decorator.oauth_required
    def get(self):
        self.response.out.write("Hello Dashboard!\n")


application = webapp.WSGIApplication([
   ('/', MainHandler),
], debug=True)

def main():
   run_wsgi_app(application)

if __name__ == '__main__':
    main()

So according to main.py if everything is fine it must print Hello Dashboard but it isn't

iJade
  • 23,144
  • 56
  • 154
  • 243

5 Answers5

19

You will actually need to add the following to your redirect URIs:

http://localhost:8080/oauth2callback

Also, you may need to append a trailing / if the above doesn't match:

http://localhost:8080/oauth2callback/
RocketDonkey
  • 36,383
  • 7
  • 80
  • 84
  • @jade And just to be sure, you set this up as a Web Application in the console, correct? – RocketDonkey Nov 04 '12 at 19:48
  • @jade For right now you are following the tutorial step-by-step? – RocketDonkey Nov 05 '12 at 06:50
  • @jade Looking at the question you just asked (about `app.yaml`), did you have it properly configured? – RocketDonkey Nov 05 '12 at 07:09
  • i have updated my question as u said.Now the error is not showing up but i'm not getting the expected output.And when i tried with the trailing / thing as http://localhost:8080/oauth2callback/ it shows the same error – iJade Nov 05 '12 at 07:19
  • @jade This shouldn't make a difference, but I've usually specified the 'final' handler as `- url: /.*` (instead of `- url: .*`). When you see the blank page, what is the URL? – RocketDonkey Nov 05 '12 at 08:14
  • 4
    It's also worth noting that when you update the dev console, it can take about 20 minutes to catch up. I had everything right, and couldn't figure out why I was still getting this error. – Captain Hypertext Jul 18 '16 at 14:14
  • Wow. The trailing slash was indeed a problem. Thanks Google! It's bad enough that you can't provide a proper JavaScript library (with an NPM package), but you'll also be very pedantic about a trailing slash. – Jake Z Jul 14 '17 at 18:44
3

using google openId I configured this

Redirect URIs: http://domain.com/authenticate/google

on https://code.google.com/apis/console, if you must create a app if you don't have one, note that must match entirely the url

Javier Gutierrez
  • 549
  • 5
  • 16
1

In main.py functions main class add (decorator.callback_path, decorator.callback_handler()), and remove

- url: /oauth2callback 
    script: oauth2client/appengine.py 

from app.yaml.

PS: You might get DownloadError if you have some proxy-configuration/webcontent-filter. If you disable these configurations or deploy it on Google Server, it will work just fine.

kundan
  • 1,278
  • 14
  • 27
1

seems like google tries to match url with being case-sensitve cause when i tried it with /Authorize and /authorize, it gave me redirect_uri_mismatch error for first one but worked for latter one

someone try and let me know if i m wrong

RohitWagh
  • 1,999
  • 3
  • 22
  • 43
0

In main.py file,

in the part where you create a wsgi application

under application = webapp.wsgiapplication(

add a handler

(decorator.callback_path,decorator.callback_handler()),
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
vickypathi
  • 11
  • 3