【发布时间】:2015-03-13 21:39:52
【问题描述】:
最近有没有人成功地将 Google 身份验证与 Burt Beckwith 出色的基于 Grails 的 Spring Security 插件相结合?我想用 Grails 2.4.3 沿着这条路走下去,经过一番鬼混(并在 https://github.com/donbeave/grails-spring-security-oauth-google 重新编译插件的 donbeave 版本)后,我找到了可以一起编译和运行的引用组合。我最终在我的 BuildConfig.groovy 中添加了以下几行:
compile ':spring-security-core:2.0-RC4'
compile ":spring-security-oauth:2.1.0-RC4"
compile ':spring-security-oauth-google:0.3.1'
然而,我发现初始化命令“grails s2-init-oauth”创建的更改并没有为我提供前进所需的所有修改。我最终在我的 config.groovy 中添加了一个块,如下所示:
oauth {
providers {
google {
api = org.grails.plugin.springsecurity.oauth.GoogleApi20
key = 'MY KEY'
secret = 'MY SECRET'
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'
}
}
}
这些配置定义在我的代码中指定了一个不存在的回调(上面称为 ./oauth/google/callback)。在我从推荐的示例 (https://github.com/bagage/grails-google-authentification-example) 中引入控制器后,将“/springSecurityOAuth/onSuccess”替换为“/oauth/google/callback”,(并通过 Google Developers Console 通过重定向 URL 注册)我发现我的 onSuccess方法确实被调用了,但是控制器中引用的数据结构是错误的,似乎我需要在很大程度上重写控制器逻辑才能使一切正常。我必须假设其他人希望以与我相同的方式完成基于 Google 的身份验证。某处是否有完整的操作示例?或者有人可以告诉我在尝试使用标准插件时哪里出错了?感谢您的帮助。
【问题讨论】:
标签: authentication grails plugins spring-security google-authentication