简体   繁体   English

如何使用RESTEasy在Google App Engine中实现oAuth 2.0?

[英]How do I implement oAuth 2.0 in Google App Engine with RESTEasy?

I am developing a Google App Engine REST service and I want to use oAuth 2.0 for authentication. 我正在开发Google App Engine REST服务,我想使用oAuth 2.0进行身份验证。 I added the following code to my service methods to check for a valid user and it works in that it throws an exception when I am not authenticated. 我将以下代码添加到我的服务方法中以检查有效用户,并且它在我未经过身份验证时抛出异常。

try 
{
    final OAuthService oauth = OAuthServiceFactory.getOAuthService();
    final User user = oauth.getCurrentUser();
}
catch (final OAuthRequestException e)
{
    throw new RuntimeException(e);
}

Now I want to authenticate against this with command line programs that are written in Java and Python. 现在,我想使用Java和Python编写的命令行程序对此进行身份验证。

I have spent hours searching Google and StackOverflow both and I can't find a single lucid example of how to authenticate against my GAE application with a non-browser application that makes any sense. 我花了几个小时搜索谷歌和StackOverflow两个,我找不到一个清晰的例子,说明如何使用非浏览器应用程序对我的GAE应用程序进行身份验证。 I found lots of examples on how to authenticate against Google's own API's but nothing about authenticating against my own Google App Engine application. 我找到了很多关于如何对Google自己的API进行身份验证的示例,但没有关于针对我自己的Google App Engine应用程序进行身份验证的示例。

Can someone provide a instructions on how to authenticate against a Google App Engine application with either Java or Python? 有人可以提供有关如何使用Java或Python对Google App Engine应用程序进行身份验证的说明吗?

Solution

I finally got OAuth 2.0 working on my Google App Engine application. 我终于在我的Google App Engine应用程序上运行了OAuth 2.0。 I have uploaded some example command line tool client code to my GitHub account. 我已经将一些示例命令行工具客户端代码上传到我的GitHub帐户。 It is way too much code to publish here in code boxes. 在代码框中发布此代码的代码太多了。 I will update this answer when I do a complete blog post about how I got it working and how the code works. 当我完成一篇关于如何使其工作以及代码如何工作的完整博客文章时,我将更新此答案。

RESTEasy 高枕无忧

Use the code posted in my question to access the User that is authenticated as the first thing in each service method, it will throw and exception if the user isn't authenticated. 使用我的问题中发布的代码来访问作为每个服务方法中的第一件事进行身份验证的User ,如果用户未经过身份验证,它将抛出异常。

Credits 积分

Thanks to Fábio Uechi for posting some code that mostly worked and just needed some updating. 感谢FábioUechi发布了一些主要工作且只需要更新的代码。 I did more than a little updating and refactored it out a good bit from what he had done . 我做了一点点更新,并从他的工作中重新做了很多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM