如何绕过Oauth2和GAE的本地登录屏幕 [英] How to Bypass Local Login Screen with Oauth2 and GAE

查看:329
本文介绍了如何绕过Oauth2和GAE的本地登录屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google提供的Oauth2装饰器。现在我只想通过使用GAE通过Oauth2向Google进行非常简单的登录。我在本地运行以进行测试,并已成功通过Google进行身份验证;但是,在Google屏幕进行身份验证之前,它始终向我显示在本地主机上运行的本地登录屏幕(// localhost:14080 / _ah / login?continue = http%3A // localhost%3A14080 /)。我不知道为什么我会得到这个本地登录屏幕,它似乎没有任何影响后面的Google登录屏幕。我想知道如何避免这个本地登录屏幕?非常简单的代码用于测试:

  import webapp2 
从apiclient.discovery导入jinja2
import build
from google.appengine.api从oauth2client.appengine导入用户
导入OAuth2Decorator


template_dir = os.path.join(os.path.dirname(__ file__), 模板)
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir))

decorator = OAuth2Decorator(
client_id ='id给出的google',
client_secret ='google提供的秘密',
scope ='https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email ')

class Handler(webapp2.RequestHandler):

def write(self,* a,** kw):
self.response.out.write (* a,** kw)
$ b $ def render_str(self,template,** params):
t = jinja_env.get_template(template)
return t.render(params)

def render(self,template,** kw):
self.write(self.render_str(template,** kw))

class MainHandler(Handler):
@ decorator.oauth_required
def get(self):
service = build('oauth2','v2',http = decorator.http())
request = service.userinfo()。get()。execute()
self.write (request [email])

app = webapp2.WSGIApplication([
('/',MainHandler),
(decorator.callback_path,decorator.callback_handler())
],debug = True)


解决方案

oauth2装饰器依赖于使用appengine登录的用户来运行(它使用用户标识来存储oauth2凭证),所以无需编写自己的代码,就不可能避免出现屏幕 - 在生产中,登录将被记住长达30天。


I am working with the Oauth2 Decorator provided by Google. Right now I am just trying to do a very simple login via Oauth2 to Google using GAE. I am running locally for test purposes and have been successful in authenticating with Google; however, prior to the Google screen for authentication it always presents me with a local login screen running on localhost (//localhost:14080/_ah/login?continue=http%3A//localhost%3A14080/). I am not sure why I am getting this local login screen which does not appear to have any bearing on the Google login screen that comes after. I am wondering how to avoid this local login screen? Very simple code for test purposes:

import webapp2
import jinja2
from apiclient.discovery import build
from google.appengine.api import users
from oauth2client.appengine import OAuth2Decorator


template_dir = os.path.join(os.path.dirname(__file__), "templates")
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir))

decorator = OAuth2Decorator(
  client_id='the id given by google',
  client_secret='the secret given by google',
  scope='https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email')

class Handler(webapp2.RequestHandler):

    def write(self, *a, **kw):
        self.response.out.write(*a, **kw)

    def render_str(self, template, **params):
        t = jinja_env.get_template(template)
        return t.render(params)

    def render(self, template, **kw):
        self.write(self.render_str(template,**kw))

class MainHandler(Handler):
    @decorator.oauth_required
    def get(self):
        service = build('oauth2', 'v2', http=decorator.http())
        request = service.userinfo().get().execute()
        self.write(request["email"])

app = webapp2.WSGIApplication([
    ('/', MainHandler),
    (decorator.callback_path, decorator.callback_handler())
], debug=True)

解决方案

The oauth2 decorator relies on having an appengine-logged-in user to function (it uses the user-id to store the oauth2 credentials), so without writing your own code, it isn't possible to avoid having the screen appear - in production, the login will be remembered for up to 30 days.

这篇关于如何绕过Oauth2和GAE的本地登录屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆