GWT和AppEngine中的Google Oauth2 [英] Google Oauth2 in GWT and AppEngine

查看:222
本文介绍了GWT和AppEngine中的Google Oauth2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为Google云端硬盘实施身份验证:

https://google-developers.appspot.com/drive/auth/web-server



第一,用户被重定向到Google登录页面进行身份验证时并不明显。看起来他们并没有显示出这一部分。

第二,它不显示回拨代码。我想我可以想出来,并需要添加一个新的servlet或服务或EntryPoint,但可能会与GWT棘手。



第三,也是最重要的,我保留得到一个ClassNotFoundException,即使这个类存在并且它编译的很好。



pre $ 引起:java.lang.NoClassDefFoundError:com / google / API /客户/ HTTP / HttpRequestInitializer $ b。在com.onix.sdm.server.SDMServiceImpl.loginServer(SDMServiceImpl.java:37)
$ b在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
在sun.reflect.NativeMethodAccessorImpl.invoke(来源不明)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(来源不明)
在java.lang.reflect.Method.invoke(来源不明)
在com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
在com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java: 561)
... 40 more
引起:java.lang.ClassNotFoundException:com.goog le.api.client.http.HttpRequestInitializer
at java.net.URLClassLoader $ 1.run(Unknown Source)
at java.net.URLClassLoader $ 1.run(Unknown Source)
at java。 security.AccessController.doPrivileged(本机方法)$ b $在java.net.URLClassLoader.findClass(未知源)$ b $在java.lang.ClassLoader.loadClass(未知源)
在com.google。 appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:215)
。在java.lang.ClassLoader.loadClass(未知来源)
... 47更
  

> 37 DriveAuthentication da = new DriveAuthentication(); //与MyClass相同

那么如何将Google Oauth2添加到GWT?

解决方案

GWT是一种客户端技术,但是您发布的链接用于服务器认证。因此,第一步是决定要使用哪种方法。



如果您需要server auth,那么您发布的链接是正确的,GWT将对此一无所知。您的GWT应用程序将使用RPC / REST等方式调用您的服务器,并且您的服务器将执行Drive访问。另一方面,如果您要执行客户端身份验证,那么您需要此链接 https://developers.google.com/accounts/docs/OAuth2UserAgent ,其中描述了您需要发布的网址。我的建议是远离图书馆,理解并发送原始URL。

I'm trying to implement authentication for Google Drive:

https://google-developers.appspot.com/drive/auth/web-server

1st, it's not obvious when the user is redirected to the Google login page to authenticate. It doesn't appear they are showing that part.

2nd, it doesn't show the call back code. I think I can figure that out and will need to add a new servlet or service or EntryPoint, but might be tricky with GWT.

3rd, and most important, I keep getting a ClassNotFoundException even though the class exists and it compiles fine.

Caused by: java.lang.NoClassDefFoundError: com/google/api/client/http/HttpRequestInitializer
    at com.onix.sdm.server.SDMServiceImpl.loginServer(SDMServiceImpl.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
    ... 40 more
Caused by: java.lang.ClassNotFoundException: com.google.api.client.http.HttpRequestInitializer
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:215)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 47 more

It is dying on this line:

37      DriveAuthentication da = new DriveAuthentication(); // Same as MyClass

So how do you add Google Oauth2 into GWT?

解决方案

GWT is a client technology, but the link you posted is for server auth. So the first step is to decide which method you want to use.

If you want server auth, then the link you posted is correct and GWT will know nothing about it. Your GWT app will call you server using RPC/REST etc, and your server will do the Drive access.

On the other hand, if you want to do client auth, then you'll need this link https://developers.google.com/accounts/docs/OAuth2UserAgent which describes the URLs you need to post to. My recommendation is to stay away from the libraries, and understand and send the raw URLs yourself.

这篇关于GWT和AppEngine中的Google Oauth2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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