Apache Oltu Spring Security OAuth2和Google集成 [英] Apache Oltu Spring Security OAuth2 and Google Integration

查看:234
本文介绍了Apache Oltu Spring Security OAuth2和Google集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该参考文献纯粹取自以下网站:-

The reference being purely taken from following sites:-

http://www.oodlestechnologies.com /blogs/OAuth-2.0-implementation-in-Spring-Framework

我已经开发了Facebook的String Security OAuth2集成示例,现在我期待着开发 Security OAuth2 Google (以及后来的Github)集成示例,其中将提供AppID和Secret以获取"access_token"和"refresh_token"等用于访问受保护的资源,例如UserDetails等.

I've developed String Security OAuth2 Facebook integration example, Now I'm looking forward to developed the Security OAuth2 Google (and later Github) integration example where AppID and Secret will be provided to get "access_token" and "refresh_token" etc to be used to access the protected resources like UserDetails etc..

因此,第一步是在 http://code.google.com/apis/console上注册应用.因此,它为我提供了客户端ID"和客户端机密",并且我还配置了重定向URI,完成!

So, first step will be register App on http://code.google.com/apis/console. So it gives me "Client ID" and "Client secret", also I've configured Redirect URI, Done !

现在我已经开始编写实际的Apache OAuth客户端,但是我不确定我需要提供哪些参数(类似地,我提供了Facebook Integration,这些参数在进行Google搜索时很容易在Facebook上可用,但是找不到) (对于Google),请向我提供以下空白参数应提供的值-

Now I've started writing actual Apache OAuth client, but I'm not sure what parameters I need to provide (similarly I provide for Facebook Integration, those parameters were easily available on facebook,while doing google search, but not found for Google), Please provide me suggestions what values should be given for the following blank parameters -

我想我已经提供了足够的信息,所以对任何指导/帮助/链接都表示赞赏.

I think I've provided enough information, so any guidance / help / links is appreciated.

OAuthClientRequest request = OAuthClientRequest
                .authorizationLocation("")
                .setClientId("3kT21Hlkzzt5eV1")
                .setRedirectURI("http://localhost:8080/apache-oltu/google/redirect")
                .setResponseType("")
                .setScope("")
                .buildQueryMessage();

以下代码是为回调而开发的

The following code is developed for callback

private void getAccessToken(String authorizationCode) throws OAuthSystemException, OAuthProblemException {
        OAuthClientRequest request = OAuthClientRequest
                .tokenLocation("")
                .setGrantType()
                .setClientId("3kT21H5EO3zzt5eV1")
                .setClientSecret("1kT21Hdlkzzt5eV1")
                .setRedirectURI("http://localhost:8080/apache-oltu/google/redirect")
                .setCode()
                .buildBodyMessage();

添加了以下代码来获取受保护的资源,例如用户个人资料:

Added the following code to get protected resources like user profile:

request= new OAuthBearerClientRequest("https://www.googleapis.com/auth/userinfo.profile").
                    setAccessToken(oAuthResponse.getAccessToken()).
                    buildQueryMessage();

推荐答案

有关完整示例,请参见此处:

See here for a complete example:

查看全文

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