我在Google App Engine上有一个应用程序,我使用了this tutorial中描述的webapp2身份验证(因此Google帐户API不会用于用户帐户管理)。
因此,我使用this Google tutorial来实施Google+登录。前端工作正常,但是我遇到了回调问题。我想在没有Flask的情况下这样做,因为它似乎唯一用于生成响应。回调第一部分的原始代码是:
if request.args.get('state', '') != session['state']:
response = make_response(json.dumps('Invalid state parameter.'), 401)
response.headers['Content-Type'] = 'application/json'
return response
为了摆脱Flask依赖,我把它重写为:
if self.request.get('state') != self.session.get('state'):
msg = json.dumps('Invalid state parameter.')
self.response.headers["Content-Type"] = 'application/json'
self.response.set_status(401)
return self.response.out.write(msg)
问题是,self.request.get(' state')什么都不返回。我猜这是因为我没有正确地阅读回复,但是我不知道如何做对。
启动回调的Javascript是:
function signInCallback(authResult) {
if (authResult['code']) {
// Send the code to the server
$.ajax({
type: 'POST',
url: '/signup/gauth',
contentType: 'application/octet-stream; charset=utf-8',
success: function(result) {
console.log(result),
processData: false,
data: authResult['code']
});
} else if (authResult['error']) {
// There was an error.
// Possible error codes:
// "access_denied" - User denied access to your app
// "immediate_failed" - Could not automatially log in the user
console.log('There was an error: ' + authResult['error']);
}
}