使用 Grails 创建 Google 登录
Creating a Google Login using Grails
我正在尝试在 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'
}
并且我已将以下块添加到我的 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" class。但是,当我 运行 我的应用程序时,我收到一条错误消息...
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 Plugin.
为此,我在 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。
这是因为您在配置中使用了 debug = true。配置属性中不存在。
我正在尝试在 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'
}
并且我已将以下块添加到我的 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" class。但是,当我 运行 我的应用程序时,我收到一条错误消息...
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 Plugin.
为此,我在 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。
这是因为您在配置中使用了 debug = true。配置属性中不存在。