Following are the steps to get connected to linkedIn in grails:
1. First of all install oauth plugin ,
Plugins{
runtime “:oauth:2.1.0″
}
alternatively install it by grails install-plugin oauth
2. In Config.groovy file, add following
oauth {
providers {
linkedin {
api = org.scribe.builder.api.LinkedInApi
key = ‘xxx’
secret = ‘yyy’
callback = “http://localhost:8080/test2/oauth/linkedin/callback”
successUri = “http://localhost:8080/test2/oauthCallBack/linkedin”
failureUri = “http://localhost:8080/test2/oauthCallBack/linkedinFailure”
requestTokenUrl = “https://api.linkedin.com/uas/oauth/requestToken”
accessTokenUrl = “https://api.linkedin.com/uas/oauth/accessToken”
authUrl = “https://api.linkedin.com/uas/oauth/authorize”
}
}
}
grails.linkedin.api.url = “http://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,date-of-birth)?format=json”
3. In your GSP file add this ,
<oauth:connect provider=”linkedin”>Connect</oauth:connect>
4. Add handler for response, i.e. edit OauthCallBackController as following:
def linkedin() {
Token linkedinAccessToken = (Token) session[oauthService.findSessionKeyForAccessToken('linkedin')]
def linkedInResponse = oauthService.getLinkedInResource(linkedinAccessToken, grailsApplication.config.grails.linkedin.api.url)
def linkedinParsedResponse = JSON.parse(linkedInResponse?.getBody())
User user = User.findByLinkedInId(linkedinParsedResponse['id'])
if (user) {
springSecurityService.reauthenticate(user.username)
} else {
…
}
}
def linkedinFailure() {
render “I am back..,.”
}
ProsperaSoft offers Grails development solutions. You can email at info@prosperasoft.com to get in touch with ProsperaSoft Grails experts and consultants.