如何检查用户是否通过API登录到他的谷歌帐户? [英] How to check whether a user is logged into his google account through API?

查看:176
本文介绍了如何检查用户是否通过API登录到他的谷歌帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个页面来显示用户可访问的文档预览。



预览我使用的是iframe,其中src = https://docs.google.com/viewer?authuser=0&srcid= {a document id}



这里的问题是当用户没有登录时显示一个空白的iframe。

如果当前用户没有登录,我想将用户重定向到Google登录页面,然后显示预览文档的页面。



对于此功能,我将首先检查用户是否使用Google登录。



我认为google在iframe的情况下有一些限制,所以它不会重定向到登录页面。



我怎样才能通过API实现它?

解决方案

如果您使用App Engine,请执行以下操作:

要查看显示谷歌文档的页面必须已经检查您是否已经登录。



只要con请指出Google用户-API。一切都在这里描述:



https://developers.google.com/appengine/docs/java/users/overview



并在web.xml中设置安全限制
https://developers.google.com/appengine/docs/java / config / webxml#Security_and_Authentication

 < security-constraint> 
< web-resource-collection>
< url-pattern> / page_shows_google_doc< / url-pattern>
< / web-resource-collection>
< auth-constraint>
<角色名称> *< /角色名称>
< / auth-constraint>
< / security-constraint>


I am developing a page to show preview of documents accessible to a user.

For previewing I am using an Iframe with src = https://docs.google.com/viewer?authuser=0&srcid={a document id}

The problem here is that when the user is not logged in it shows a blank iframe.

I want to redirect the user to google login page if the current user is not logged in and then display the page previewing the document.

For this functionality I will have to check first that whether the user is logged in with google or not.

I think google has some restrictions imposed in case of iframe so it not redirecting to the login page.

How can I implement it through API?

解决方案

If you use App Engine do it like this:

To view the page which is showing the google doc must already be checking if you are logged in.

Just configure the Google Users-API. Everything is described here:

https://developers.google.com/appengine/docs/java/users/overview

And set the security constraints in web.xml https://developers.google.com/appengine/docs/java/config/webxml#Security_and_Authentication

<security-constraint>
    <web-resource-collection>
        <url-pattern>/page_shows_google_doc</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>*</role-name>
    </auth-constraint>
</security-constraint>

这篇关于如何检查用户是否通过API登录到他的谷歌帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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