我正在设置以下内容:
BuildConfig:
plugins {
build ":tomcat:7.0.52.1"
compile ":hibernate:3.6.10.13"
compile ':spring-security-core:2.0-RC2'
compile ':spring-security-oauth:2.0.2'
compile ':spring-security-oauth-facebook:0.1'
}
配置:
grails.plugin.springsecurity.oauth.domainClass = 'com.mobilizr.OAuthID'
oauth{
providers{
facebook {
api = org.scribe.builder.api.FacebookApi
key = '111111'
secret = '333veeerysecret23234234234'
successUri = '/oauth/facebook/success'
failureUri = '/oauth/facebook/error'
callback = "${baseURL}/oauth/facebook/callback"
}
}
}
点击链接时:
<oauth:connect provider="facebook" id="facebook-connect-link">Facebook</oauth:connect>
我得到例外:
java.lang.IllegalArgumentException: Must provide a valid url as callback. Facebook does not support OOB
我不知道这应该是什么意思。页面spring security oauth facebook并未给出太多详细信息。有没有人有想法,或者可能是FB-auth的工作样本?
答案 0 :(得分:2)
baseURL
是您的应用程序服务器URL。将baseURL
替换为您的应用程序服务器URL。例如,
callback = "http://localhost:8080/mySampleApp/oauth/facebook/callback"
并解决了您的错误。
还可以替换successUri
和failureUri
。例如,
oauth {
providers {
facebook {
api = org.scribe.builder.api.FacebookApi
key = 'Your_Key'
secret = 'Your_Secret'
successUri = 'http://localhost:8080/mySampleApp/oauthCallback/success'
failureUri = 'http://localhost:8080/mySampleApp/oauthCallback/error'
callback = "http://localhost:8080/mySampleApp/oauth/facebook/callback"
}
}
}
并提供从Facebook获取数据的代码。我编写了代码来获取用户信息:
import grails.converters.JSON
import org.scribe.model.Token
class OauthCallbackController {
def oauthService
def index() {}
def success() {
Token facebookAccessToken = (Token) session[oauthService.findSessionKeyForAccessToken('facebook')]
if (facebookAccessToken) {
def facebookResource = oauthService.getFacebookResource(facebookAccessToken, "https://graph.facebook.com/me")
def facebookResponse = JSON.parse(facebookResource?.getBody())
Map data = [id: facebookResponse.id, username: facebookResponse.username, name: facebookResponse.name, email: facebookResponse.email,
first_name: facebookResponse.first_name, last_name: facebookResponse.last_name, birthday: facebookResponse.birthday,
gender: facebookResponse.gender, link: facebookResponse.link, work: facebookResponse.work, hometown: facebookResponse.hometown,
education: facebookResponse.education]
render data
} else {
flash.error = "Token not found."
render view: '/index'
}
}
def error() {
render params
}
}
希望这会有所帮助: - )