我进行了以下设置:
构建配置:
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>
我得到了异常(exception):
java.lang.IllegalArgumentException: Must provide a valid url as callback. Facebook does not support OOB
我不知道这是什么意思。页面spring security oauth facebook没有给出太多细节。有谁有一个想法,或者也许是 FB-auth 的工作示例?
最佳答案
回调 URL 中的
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
}
}
希望这有帮助:-)
关于grails - 使用 facebook oauth2.0 的 Grails 2.3.8 应用程序中出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23614352/