In my previous article I described how to begin friendship of spring-social and tapestry:
SpringSocial and Tapestry. Let's be connected.
There are 2 implementations of Twitter and Facebook templates in spring-social library. They are for OAuth1 and OAuth2 protocols respectively. But what about other APIs that also works with OAuth protocol?
Lets look on new Google OAuth 2 API. You can play with it here:
OAuth 2.0 Playground
Firstly we should decide what we need. In this article I will provide information mostly about Google user profile.
Lets look on Facebook implementation. It consists of:
First of all authorize and access token urls:
https://accounts.google.com/o/oauth2/auth
https://accounts.google.com/o/oauth2/token
All this API operations are based on url:
https://www.googleapis.com/oauth2/v2
Then to get user info we need to use scope:
https://www.googleapis.com/auth/userinfo.profile
and request url:
https://www.googleapis.com/oauth2/v2/userinfo
The scope will affect on permited data. Then we will need to parse JSON responce all needed user information.
NOTE: All this information is available in OAuth Playground application mentioned earlier. And don't forget about "Find available request URIs" button.
So Google API for SpringSocial will look like this:
Then we need to create binding module for spring rest utils. Of course, we can use mappings directly in our beans and everething will work as expected. But the main idea of binding module is to separate POJO objects from mapping structures.
This bindings should be registered in our implementation:
And the last part is oauth template and oauth service provider:
Now we are able to use it anywhere, e.g. to use it within yapestry application as in my previous article.
Updated example can be found here:
T5-Examples App
Sources here:
GitHub Sources
GitHub? :)
SpringSocial and Tapestry. Let's be connected.
There are 2 implementations of Twitter and Facebook templates in spring-social library. They are for OAuth1 and OAuth2 protocols respectively. But what about other APIs that also works with OAuth protocol?
Lets look on new Google OAuth 2 API. You can play with it here:
OAuth 2.0 Playground
Firstly we should decide what we need. In this article I will provide information mostly about Google user profile.
Lets look on Facebook implementation. It consists of:
- API interface (Facebook, UserOperations, etc.)
- Beans for API call results, e.g. (FacebookProfile, WorkEntry, EducationEntry, etc.)
- API implementation (FacebookTemplate, UserTemplate, etc.)
- JSON Binding module to separate json binding from beans (FacebookModule, FacebookProfileMixin, etc.)
First of all authorize and access token urls:
https://accounts.google.com/o/oauth2/auth
https://accounts.google.com/o/oauth2/token
All this API operations are based on url:
https://www.googleapis.com/oauth2/v2
Then to get user info we need to use scope:
https://www.googleapis.com/auth/userinfo.profile
and request url:
https://www.googleapis.com/oauth2/v2/userinfo
The scope will affect on permited data. Then we will need to parse JSON responce all needed user information.
NOTE: All this information is available in OAuth Playground application mentioned earlier. And don't forget about "Find available request URIs" button.
So Google API for SpringSocial will look like this:
Then we need to create binding module for spring rest utils. Of course, we can use mappings directly in our beans and everething will work as expected. But the main idea of binding module is to separate POJO objects from mapping structures.
This bindings should be registered in our implementation:
And the last part is oauth template and oauth service provider:
Now we are able to use it anywhere, e.g. to use it within yapestry application as in my previous article.
Updated example can be found here:
T5-Examples App
Sources here:
GitHub Sources
GitHub? :)
No comments:
Post a Comment