Question

How to get Connected With Linked In Grails ??

Config.groovy

oauth {
    linkedin {
        requestTokenUrl="https://api.linkedin.com/uas/oauth/requestToken"
        accessTokenUrl="https://api.linkedin.com/uas/oauth/accessToken"
        authUrl="https://api.linkedin.com/uas/oauth/authorize"
        consumer.key="xxx"
        consumer.secret="xxx"
    }
}

plugin:

compile ":oauth:2.1.0"

And GSP :

  <oauth:connect provider="linkedin">Connect</oauth:connect>

But I trying to run this code.. on browser its showing this error

org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException

Tag [oauthLink] does not exist. No tag library found for namespace: g

Was it helpful?

Solution

Use oauth taglib to create button to connect with linkedin rather than g tag

<oauth:connect provider="linkedin">Connect</oauth:connect>

EDIT...................................................................................

Following is my Config.groovy

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"

and I have a OauthCallBackController with an action linkedin

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..,."
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top