Apache Oltu Spring OAuth2 Security and Google Integration

The link is purely taken from the following sites: -

I have developed an example of integration of String Security OAuth2 Facebook, now I look forward to developing an example of integration of Google OAuth2 (and a later version of Github), where AppID and Secret will be available to get "access_token" and "refresh_token" etc. which will be used to access secure resources such as UserDetails, etc.

So, the first step is to register the application at http://code.google.com/apis/console . So it gives me โ€œClient IDโ€ and โ€œClient secretโ€, also I configured the redirect URI, Done!

Now I started writing the actual Apache OAuth client, but I'm not sure what parameters I need to provide (similarly I provide for integration with Facebook, these parameters were easily accessible on facebook, while doing a search on Google, but could not find for Google), Please provide me what values โ€‹โ€‹should be specified for the following empty parameters -

I think I have provided enough information, so any recommendations / links / links are welcome.

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

The following code has been 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(); 

The following code has been added to obtain secure resources, such as a user profile:

 request= new OAuthBearerClientRequest("https://www.googleapis.com/auth/userinfo.profile"). setAccessToken(oAuthResponse.getAccessToken()). buildQueryMessage(); 
+3
spring-security google-oauth google-oauth2 oltu
source share
2 answers

I developed an example of Apache Oltu and Spring , and it works great on my end.

You need to enable the Google+ API, as suggested by @prtk_shah. Thanks.

You need to go to https://console.developers.google.com/project?authuser=0 and click on your project, in my case it is "apache-oltu", in your open the API APIs and auth โ†’ API Find the Google+ API and enable it.

Here you can see this screen. enter image description here

So, I will modify your code below, it should look like this:

(IMP). Your customer ID should be like this: For example: (755670439314-jcumfghnkmcm72hf40beikvoatknstml.apps.googleusercontent.com), please make sure that it is correct. Fyi is use as it is provided by the Google Developer Console.

 OAuthClientRequest request = OAuthClientRequest .authorizationLocation("https://accounts.google.com/o/oauth2/auth") .setClientId("3kT21Hlkzzt5eV1.apps.googleusercontent.com") .setRedirectURI("Give your projects redirect URI") .setResponseType("responsecode") .setScope("openId profile email") .buildQueryMessage(); 

The callback code should be:

 private void getAccessToken(String authorizationCode) throws OAuthSystemException, OAuthProblemException { OAuthClientRequest request = OAuthClientRequest .tokenLocation("https://accounts.google.com/o/oauth2/token") .setGrantType(GrantType.AUTHORIZATION_CODE) .setClientId("give your complete client id") .setClientSecret("give your secret") .setRedirectURI("This will be your callback or Redirect URL (Give it correctly)") .setCode(authorizationCode) .buildBodyMessage(); 

This is what I get in my example, I just wanted to show you

enter image description here

Hope this will be helpful.

0
source share

All Articles