我正在尝试在 Grails 项目中创建一个 Google 登录选项。我是 Grails 的新手,正在使用 2.4.4 版本,因为这是安装时的最新版本。在大量搜索 Grails 插件之后,我将最后 4 行添加到了我的 BuildConfig.groovy 文件中:
plugins {
// plugins for the build system only
build ":tomcat:7.0.55"
// plugins for the compile step
compile ":scaffolding:2.1.2"
compile ':cache:1.1.8'
compile ":asset-pipeline:1.9.9"
// plugins needed at runtime but not for compilation
runtime ":hibernate4:4.3.6.1" // or ":hibernate:3.6.10.18"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
// Uncomment these to enable additional asset-pipeline capabilities
//compile ":sass-asset-pipeline:1.9.0"
//compile ":less-asset-pipeline:1.10.0"
//compile ":coffee-asset-pipeline:1.8.0"
//compile ":handlebars-asset-pipeline:1.3.0.3"
// added these...
compile ':spring-security-core:2.0-RC4'
compile ':spring-security-oauth:2.1.0-RC4'
compile ':spring-security-oauth-google:0.3.1'
}
我已将以下 block 添加到我的 Config.groovy 文件中:
oauth {
providers {
google {
api = org.grails.plugin.springsecurity.oauth.GoogleApi20
key = app id
secret = secret key
successUri = '/oauth/google/success'
failureUri = '/oauth/google/error'
callback = "${baseURL}/oauth/google/callback"
scope = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'
}
debug = true
connectTimeout = 5000
receiveTimeout = 5000
}
我还运行了“grails s2-init-oauth”并创建了一个“OAuthID”类。但是,当我运行我的应用程序时,我收到一条错误消息,提示...
Error creating bean with name 'oauthService': Invocation of init method failed; nested exception is groovy.lang.MissingPropertyException: No such property: key for class: java.lang.Boolean
有没有人遇到过这个问题并可以提出解决方案?在这一点上,即使是对导致错误消息的原因的解释也会对我有所帮助?
最佳答案
我还使用 Google 创建了登录。为此,我使用了 Oauth 插件 .
为此,我在 BuildConfig.groovy 中添加了
compile ":oauth:2.1.0"
在 Config.groovy 中,
oauth {
providers {
google {
api = org.scribe.builder.api.GoogleApi
key = '583594517530-72ipieehn58c5160rvgdsodjgiifoedn.apps.googleusercontent.com'
secret = 'pBtTg2j_EfanwNhuuAIDWW48'
scope ='https://www.googleapis.com/auth/userinfo.email'
callback = "http://localhost:8080/googleAuthen/oauth/google/callback"
successUri = "http://localhost:8080/googleAuthen/oauthCallBack/google"
}
}
}
完整代码见 this github repo .
Oauth 插件的文档是 here .
关于grails - 使用 Grails 创建 Google 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28966801/