如何开始使用Grails3和Google作为ID提供程序

时间:2017-11-06 21:04:11

标签: oauth oauth-2.0 grails3 grails-3.3

我想开始使用一个简单的Grails应用程序,它允许我的用户通过谷歌等多个openIDConnect提供商登录。

所以我开始在项目中添加一些依赖项:

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配置为auth提供商。谷歌设置似乎没问题 - 它来自另一个项目。

作为最后一步,我添加了

       <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能够调用登录并查看发生了什么。

到目前为止,这么好。成功登录谷歌后,我被重定向到http://localhost:8080/oauth2/createaccount,如果我想创建新用户或链接到现有用户,我必须选择。{/ p>

如果我尝试创建一个新的,它会失败

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

1 个答案:

答案 0 :(得分:0)

必须弄清楚这是grails-spring-security-oauth2 - 插件中的错误,但该修补程序尚未发布到Grails中央存储库:

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

相关问题