Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Oltu Spring Security OAuth2 and Google Integration

The reference being purely taken from following sites:-

  • http://syntx.io/integrating-your-java-spring-mvc-webapp-with-facebook-doing-the-oauth-dance/

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

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..

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 !

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();

1 Answers

See here for a complete example:

http://mail-archives.apache.org/mod_mbox/oltu-user/201503.mbox/%3CA562FE5D3662044186474F4174F11DAE13044C639F@iowajhnex126.iowa.gov.state.ia.us%3E

like image 133
Saqib Ali Avatar answered Feb 08 '26 02:02

Saqib Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!