我想开始使用一个简单的 Grails 应用程序,它允许我的用户通过几个 openIDConnect 提供商(如 google)登录。
所以我开始在我的项目中添加一些依赖项:
compile 'org.grails.plugins:spring-security-core:3.2.0'
compile 'org.grails.plugins:spring-security-oauth2:1.1.0'
compile 'org.grails.plugins:spring-security-oauth2-google:1.1.0'
spring-security
并通过初始化
grails s2-quickstart com.yourapp User Role
并oauth2
通过
grails init-oauth2 com.yourapp User OAuthID
然后我添加了
static hasMany = [oAuthIDs: OAuthID]
到我的User
. 在application.yaml
我已将 google 配置为身份验证提供程序。谷歌设置似乎没问题 - 它来自另一个项目。
作为最后一步,我添加了
<oauth2:connect provider="google" id="google-connect-link">Google</oauth2:connect>
Logged with google?
<oauth2:ifLoggedInWith provider="google">yes</oauth2:ifLoggedInWith>
<oauth2:ifNotLoggedInWith provider="google">no</oauth2:ifNotLoggedInWith>
让我index.gsp
能够调用登录并查看发生了什么。
到目前为止,一切都很好。使用 google 成功登录后,我被重定向到http://localhost:8080/oauth2/createaccount
我必须选择的位置,如果我想创建一个新用户或链接到现有用户。
如果我尝试创建一个新的,它会失败
Class
java.lang.NullPointerException
Message
Request processing failed; nested exception is org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: [views/index.gsp:60] Error executing tag <oauth2:ifLoggedInWith>: Cannot invoke method sessionKeyForAccessToken() on null object
Caused by
Cannot invoke method sessionKeyForAccessToken() on null object
(顺便说一句:您必须使用强密码以避免出现另一个错误消息)
在 Windows 10 上运行的 Grails V3.3.1