2017-11-06 15 views
0

Google과 같은 몇 가지 openIDConnect 공급자를 통해 로그인 할 수있는 간단한 Grails 앱을 시작하고자합니다. Grails3 및 Google을 ID 제공자로 시작하는 방법

그래서 난 내 프로젝트에 일부 종속성을 추가하기 시작 :

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' 

grails init-oauth2 com.yourapp User OAuthID 
다음

내가

를 추가했습니다 통해

grails s2-quickstart com.yourapp User Role 

oauth2를 통해 spring-security을 초기화

static hasMany = [oAuthIDs: OAuthID] 

to User. application.yaml에서 인증 공급자로 google을 구성했습니다. Google 설치가 괜찮은 것 같습니다. 다른 프로젝트에서 가져옵니다.

는 마지막 단계로, 나는 로그인을 호출하고 무슨 일이 일어나고 있는지 볼 수 내 index.gsp

 <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> 

을 추가했습니다.

지금까지 그렇게 좋았습니다. 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 

실패 (BTW : 다른 오류 메시지를 방지하기 위해 강력한 암호를 사용해야합니다)

Grails의 V3.3.1 실행을 윈도우 10에

답변