Fork me on GitHub

OAuth (v1.9)

pac4j allows you to login with identity providers using the OAuth v1.0 and v2.0 protocol.

1) Dependency

You need to use the following module: pac4j-oauth.

Example (Maven dependency):

<dependency>
    <groupId>org.pac4j</groupId>
    <artifactId>pac4j-oauth</artifactId>
    <version>${pac4j.version}</version>
</dependency>

2) Available clients

a) Generic clients

You can use the GenericOAuth20Client or the GenericOAuth20StateClient clients to login with an OAuth 2.0 server. It returns a GenericOAuth20Profile.

Example:

GenericOAuth20Client client = new GenericOAuth20Client();
client.setAttributesDefinition(new GitHubAttributesDefinition());
client.setAuthUrl("https://github.com/login/oauth/authorize");
client.setTokenUrl("https://github.com/login/oauth/access_token");
client.setProfileUrl("https://api.github.com/user");
client.setKey("62374f5573a89a8f9900");
client.setSecret("01dd26d60447677ceb7399fb4c744f545bb86359");
client.setCallbackUrl("http://localhost:8080/callback");
client.setScope("user");

b) Specific clients

Many clients are available to login with many identity providers:

Identity provider Client User profile
BitBucket BitbucketClient BitbucketProfile
CAS server using OAuth protocol CasOAuthWrapperClient CasOAuthWrapperProfile
DropBox DropBoxClient DropBoxProfile
Facebook FacebookClient FacebookProfile
Foursquare FoursquareClient FoursquareProfile
Github GitHubClient GitHubProfile
Google Google2Client Google2Profile
LinkedIn LinkedIn2Client LinkedIn2Profile
Odnoklassniki OkClient OkProfile
ORCiD OrcidClient OrcidProfile
Paypal PayPalClient PayPalProfile
Strava StravaClient StravaProfile
Twitter TwitterClient TwitterProfile
Vk VkClient VkProfile
Windows Live WindowsLiveClient WindowsLiveProfile
Word Press WordPressClient WordPressProfile
Yahoo YahooClient YahooProfile

Example:

FacebookClient facebookClient = new FacebookClient("145278422258960", "be21409ba8f39b5dae2a7de525484da8");
TwitterClient twitterClient = new TwitterClient("CoxUiYwQOSFDReZYdjigBA", "2kAzunH5Btc4gRSaMr7D7MkyoJ5u1VzbOOzE8rBofs");