Code Monkey home page Code Monkey logo

playframework-linkedin's Introduction

Play Framework - Module play-linkedin 0.2.1

by Felipe Oliveira http://geeks.aretotally.in http://twitter.com/_felipera

Easily integrate LinkedIn's OAuth authentication into any Java web application using the super cool Play Framework (http://playframework.org).

Prerequisites

Register your application with LinkedIn (https://www.linkedin.com/secure/developer). LinkedIn's API documentation can be found at http://developer.linkedin.com/community/apis.

Install the module

Install the linkedin module from the modules repository:

play install linkedin

Enable the module

After installing the module, add the following to your application.conf to enable it:

module.linkedin=${play.path}/modules/linkedin-0.2.1

Configure the module

And finally, you need to configure the module by setting these properties in your application.conf (Register API Key at https://www.linkedin.com/secure/developer):

 linkedin.apiKey=YOUR_API_KEY_HERE
 linkedin.secret=YOUR_APP_SECRET_HERE
 linkedin.model=models.User
 linkedin.landUrl=/

All of the properties are required.

Usage

Step-by-Step Tutorial can be found at http://geeks.aretotally.in/integrate-linkedins-oauth-authentication-with-a-java-app-using-play-linkedin-module-version-0-2-1.

Use the linkedin.button tag in your view

The linkedin.button tag outputs a link that will prompt your users to authenticate with LinkedIn when it is clicked.

#{linkedin.button /}

Define your OAuth callback

Your linkedin.model class needs to implement a static method called @linkedinOAuthCallback@. After a user has authenticated using LinkedIn, the module will call this method with a token (String). This is your opportunity to add the user to your database, add the user to your session, or do anything else you want.

	    public static User findByLinkedInId(String linkedInId) {
	    	return find("byLinkedInId", linkedInId).first();
	    }
	    
		public static void linkedinOAuthCallback(play.modules.linkedin.LinkedInProfile profile) {
			Logger.info("Handle LinkedIn OAuth Callback: " + profile);
			User user = findByLinkedInId(profile.getId());
			String username = "linkedin:" + profile.getId();
			if(user == null || user.linkedInToken == null) {
				user = new User();
				user.fullname = (new StringBuffer().append(profile.getFirstName()).append(" ").append(profile.getLastName())).toString();
				user.linkedInId = profile.getId();
				user.industry = profile.getIndustry();
				user.headline = profile.getHeadline();
				user.pictureUrl = profile.getPictureUrl();
				user.linkedInToken = profile.getAccessToken();
				user.isAdmin = true;
				user = user.save();
			} else {
				Logger.info("Found User: " + user);
				user.linkedInToken = profile.getAccessToken();
				user.save();
			}
			if ( user == null ) {
				throw new RuntimeException("Could not store or lookup user with LinkedIn Profile: " + profile);
			}
			Session.current().put("username", username);
		}

Source Code

Fork it on Github https://github.com/feliperazeek/playframework-linkedin.

playframework-linkedin's People

Stargazers

Cleibson Gomes avatar

Watchers

James Cloos avatar Cleibson Gomes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.