首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OAuthException: google的无效响应

问OAuthException: google的无效响应
EN

Stack Overflow用户
提问于 2018-11-17 20:55:18
回答 1查看 1.4K关注 0票数 2

因此,我正在运行我的烧瓶应用程序从谷歌云外壳。在这个应用程序中,用户需要使用他们的google帐户登录。我使用云shell安装了所有必需的库。

当我在云shell中运行应用程序时,在选择了我想要登录到我的应用程序的google帐户后,就会出现这个错误。

代码语言:javascript
复制
flask_oauth.OAuthException
OAuthException: Invalid response from google

如果我从本地主机运行它,一切都很好。

任何形式的帮助都是非常感谢的。

PS:这是密码

Flask.py:

代码语言:javascript
复制
import logging
from flask import Flask, render_template, redirect, url_for, session, make_response
from flask_oauth import OAuth
from urllib2 import Request, urlopen, URLError
import MySQLdb
import os
import json

Client_Id = my client id
Client_Secret = my client secret
Redirect_URI = '/callback'

SECRET_KEY = 'funny cat'
DEBUG = True

app = Flask(__name__)
app.debug = DEBUG
app.secret_key = SECRET_KEY
oauth = OAuth()

google = oauth.remote_app('google', base_url='https://www.google.com/accounts/', authorize_url='https://accounts.google.com/o/oauth2/auth', request_token_url=None, request_token_params={'scope': 'https://www.googleapis.com/auth/userinfo.profile', 'response_type': 'code'}, access_token_url='https://accounts.google.com/o/oauth2/token', access_token_method='POST', access_token_params={'grant_type': 'authorization_code'}, consumer_key=Client_Id, consumer_secret=Client_Secret)

@app.route('/')
def index():
    return render_template("webpage1.html")                  

@app.route('/login',methods=['post','get'])
def login():
    access_token = session.get('access_token')
    if access_token is None:
        return redirect(url_for('direct'))

    access_token = access_token[0]
    headers = {'Authorization': 'OAuth '+access_token}
    req = Request('https://www.googleapis.com/oauth2/v1/userinfo',
                  None, headers)
    try:
        res = urlopen(req)
    except URLError, e:
        if e.code == 401:
            session.pop('access_token', None)
            return redirect(url_for('direct'))
        return res.read()
    data = json.load(res)
    return render_template("webpage2.html", data = data)

@app.route('/direct')
def direct():
    callback=url_for('authorized', _external=True)
    return google.authorize(callback=callback)

@app.route(Redirect_URI)
@google.authorized_handler
def authorized(resp):
    access_token = resp['access_token']
    session['access_token'] = access_token, ''
    return redirect(url_for('login'))

@app.route('/logout')
def logout():
    session.pop('access_token', None)
    return redirect(url_for('index'))

@google.tokengetter
def get_access_token():
    return session.get('access_token')

if __name__ == "__main__":
    app.run(host='0.0.0.0', debug=True)

我在API中的凭据是

代码语言:javascript
复制
Authorized JavaScript origins : https://5000-dot-4778310-dot-devshell.appspot.com   
Authorized redirect URIs : https://5000-dot-4778310-dot-devshell.appspot.com/callback   

为什么同一客户端id和客户端机密的项目名称不同?

EN

回答 1

Stack Overflow用户

发布于 2018-11-18 08:54:48

这个问题实际上是如何使用运行在Google中的OAuth /设置GoogleCloud2.0。

Google 2.0授权可以分为两种模式:本地主机模式和回调模式。

本地主机模式

这要求在本地运行的web服务器的同一台计算机中执行整个身份验证过程。连接到Google域的web浏览器也必须在同一台计算机中运行。浏览器不能在另一台机器(或VM)上运行。由于Cloud没有web浏览器,所以这种模式是不可能的。

回调模式

这要求web服务器运行时配置了TLS。Google 2.0只支持HTTPS端点的回调url。这还需要经过验证的域名和SSL证书。由于您既不控制Cloud域名,也没有证书的私钥,因此不可能设置TLS。

因此,这个问题的答案是,不可能设置运行在Cloud中的服务器进程来处理GoogleCloud2.0身份验证。

在这个用户的例子中,回调URL与他的Flask服务器的配置方式不匹配。在这种情况下,无法正确配置回调URL。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53355498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档