0

我想开始使用一个简单的 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

4

1 回答 1

0

必须弄清楚这是grails-spring-security-oauth2-plugin 中的一个错误,但该修复尚未发布到 Grails 中央存储库:

https://github.com/MatrixCrawler/grails-spring-security-oauth2/issues/9

于 2017-11-06T21:04:11.000 回答