Google app engine oauth2decorator_from_clientsecrets在部署后导致开发服务器出错
我在我的Google应用程序引擎应用程序中使用了Python OAuth2装饰器。我从API控制台以json文件的形式下载了客户机机密。将应用程序部署到appspot.com后,本地版本(localhost:8080)无法工作。调用decorator.has_credentials()返回false。appspot版本运行良好 更新:代码片段(简化) 我在本地计算机中收到“无效凭据”。在appspot.com上运行良好。在部署到appspot之前,它在我的机器中工作 会发生什么Google app engine oauth2decorator_from_clientsecrets在部署后导致开发服务器出错,google-app-engine,python-2.7,oauth-2.0,Google App Engine,Python 2.7,Oauth 2.0,我在我的Google应用程序引擎应用程序中使用了Python OAuth2装饰器。我从API控制台以json文件的形式下载了客户机机密。将应用程序部署到appspot.com后,本地版本(localhost:8080)无法工作。调用decorator.has_credentials()返回false。appspot版本运行良好 更新:代码片段(简化) 我在本地计算机中收到“无效凭据”。在appspot.com上运行良好。在部署到appspot之前,它在我的机器中工作 会发生什么 提前谢谢好吧,我
提前谢谢好吧,我太傻了。我第一次忘了给用户提供一个授权链接,而不是一个错误
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')
oauth2_decorator = oauth2decorator_from_clientsecrets(
CLIENT_SECRETS,
scope='https://www.googleapis.com/auth/calendar',
message=MISSING_CLIENT_SECRETS_MESSAGE)
class MyRequestHandler(webapp2.HandleRequest):
@oauth2_decorator.oauth_aware
def get(self):
if oauth2_decorator.has_credentials():
# do stuff...
else:
self.out.write(oauth2_decorator.authorize_url())
app = webapp2.WSGIApplication([
('/', MyRequestHandler),
(oauth2_decorator.callback_path, oauth2_decorator.callback_handler())
], debug=True)
现在它可以正常工作了:-)。你可以发布一段代码片段来说明你是如何使用装饰器的吗?当然可以。我刚做完。你能添加client_secrets.json的内容吗(删除敏感信息后)?
{"web":
{
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"client_secret":"MY_CLIENT_SECRET",
"token_uri":"https://accounts.google.com/o/oauth2/token",
"client_email":"MY_CLIENT_ID@developer.gserviceaccount.com",
"redirect_uris":[
"http://MY_APP_NAME.appspot.com",
"http://localhost:8080"
],
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/MY_CLIENT_ID@developer.gserviceaccount.com",
"client_id":"MY_CLIENT_ID.apps.googleusercontent.com",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"javascript_origins":[
"http://MY_APP_NAME.appspot.com",
"http://localhost:8080"
]
}
}
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')
oauth2_decorator = oauth2decorator_from_clientsecrets(
CLIENT_SECRETS,
scope='https://www.googleapis.com/auth/calendar',
message=MISSING_CLIENT_SECRETS_MESSAGE)
class MyRequestHandler(webapp2.HandleRequest):
@oauth2_decorator.oauth_aware
def get(self):
if oauth2_decorator.has_credentials():
# do stuff...
else:
self.out.write(oauth2_decorator.authorize_url())
app = webapp2.WSGIApplication([
('/', MyRequestHandler),
(oauth2_decorator.callback_path, oauth2_decorator.callback_handler())
], debug=True)