Grails oauth插件:未知的提供商linkedin,请检查您的配置

时间:2013-09-05 06:53:14

标签: grails oauth-2.0 grails-2.0 grails-plugin grails-controller

如何与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"
    }
}

插件:

compile ":oauth:2.1.0"

和GSP:

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

但我试图在浏览器上运行此代码..它显示此错误

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

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

1 个答案:

答案 0 :(得分:2)

使用oauth taglib创建按钮以连接linkedin而非g tag

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

修改........................................... ........................................

以下是我的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"

我有一个带有动作linkedin的OauthCallBackController

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..,."
}