My GAE app uses OAUTH 2. Currently, I manually switch the redirect_uri
between http://localhost:8081/oauth2callback
and myapp.appspot.com/oauth2callback
depending on whether do local testing with dev_appserver
or if I deploy to appspot.com.
Is there some code (e.g. using os.environ
) that I can use to automate this?
Thanks!
You can get you current domain name with
os.environ['SERVER_NAME']
.You also can check this by version name:
Will be better to use
self.uri_for('callback-uri-name', _full=True)
for building callback uri if you use webapp2.You have something like this in your routes.
Then, if you'll call
self.uri_for('callback-uri-name', _full=True)
you'll get something likehttp://localhost:8080/oauth/callback
orhttp://app-id.appspot.com/oauth/callback
.For more information: http://webapp-improved.appspot.com/guide/routing.html#building-uris