In my previous post, I introduced you to Spring Social's Java bindings to popular Software-as-a-Service (SaaS) APIs such as Twitter, Facebook, LinkedIn, and TripIt. In addition to providing simple, strongly-typed Java methods for common API operations, these bindings ensure each HTTP request includes the credentials required to authorize your application to invoke the API on behalf of a user.
What my first post did not address was: how do we manage the credentials required to invoke service APIs on behalf of users? I'm pleased to say that we now have answers to that question.
Earlier this week, we announced the release of the second milestone of the Spring Social project. The most significant new feature in Spring Social 1.0.0.M2 is the introduction of a Service Provider "Connect" framework. Today I want to introduce you to this framework and show you how to use it to manage "connections" to SaaS providers.
The examples in this article are from the Spring Social Showcase. To follow along, clone the repository and follow the README to build and deploy the sample app.
Getting Spring Social
With the M2 release, Spring Social has been split into several modules:
- spring-social-core - The service provider framework, OAuth support, and core classes.
- spring-social-web - The connect controller and supporting types.
- spring-social-facebook - A service provider implementation for connecting with Facebook and support for signing into an application via Facebook.
- spring-social-twitter - A service provider implementation for connecting with Twitter and support for signing into an application via Twitter.
- spring-social-linkedin - A service provider implementation for connecting with LinkedIn.
- spring-social-tripit - A service provider implementation for connecting with TripIt.
- spring-social-github - A service provider implementation for connecting with GitHub.
- spring-social-gowalla - A service provider implementation for connecting with Gowalla.
- spring-social-test - Support for testing service provider implementations and API bindings.
Depending on your needs, you won't necessarily need all of these modules. At a minimum, you'll need the core module. You can add this to a Maven-built project with the following entry:
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-core</artifactId>
<version>1.0.0.M2</version>
</dependency>
In the likely case that you'll be using Spring Social in a web application, you'll also need the web module:
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-web</artifactId>
<version>1.0.0.M2</version>
</dependency>
Then, you'll need to add one or more of the provider modules. In our examples, we'll be talking about adding Twitter connectivity to an application, so we'll need the twitter module:
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-twitter</artifactId>
<version>1.0.0.M2</version>
</dependency>
Since we're building off of a milestone release of Spring Social, we're going to need to add Spring's milestone repository to the pom.xml file:
<repository>
<id>org.springframework.maven.milestone</id>
<name>Spring Maven Milestone Repository</name…