티스토리 뷰
grails oauth 적용한 내용입니다.
쉬지만 중간중간 막히는 부분이 있어서 그런 문제를 겪는 분들에게 도움이 될까 정리해서 공유합니다.
BuildConfig.groovy 에 다음을 추가한다.
repositories {
....
mavenRepo "https://raw.github.com/fernandezpablo85/scribe-java/mvn-repo"
mavenRepo 'http://repo.spring.io/milestone'
....
}
plugins {
...
compile ":spring-security-oauth-google:0.3.1"
...
다음 명령어를 실행한다.
grails compile
spring security 설정 및 oauth 초기화
grails s2-quickstart com.shuiky User Role
grails s2-init-oauth com.shuiky OAuthID
Config.groovy에 추가하시고 secret과 key는 각 oauth provider에게 발급받으시고 알맞게 수정해주세요
def appName = grails.util.Metadata.current.'app.name'
def baseURL = grails.serverURL ?: "http://localhost:${System.getProperty('server.port', '8080')}/${appName}"
oauth {
debug = true
providers {
facebook {
api = org.scribe.builder.api.FacebookApi
key = 'oauth_facebook_key'
secret = 'oauth_facebook_secret'
successUri = '/oauth/facebook/success'
failureUri = '/oauth/facebook/failure'
callback = "${baseURL}/oauth/facebook/callback"
}
twitter {
api = org.scribe.builder.api.TwitterApi
key = 'oauth_twitter_key'
secret = 'oauth_twitter_secret'
successUri = '/oauth/twitter/success'
failureUri = '/oauth/twitter/failure'
callback = "${baseURL}/oauth/twitter/callback"
}
linkedin {
api = org.scribe.builder.api.LinkedInApi
key = 'oauth_linkedin_key'
secret = 'oauth_linkedin_secret'
successUri = '/oauth/linkedin/success'
failureUri = '/oauth/linkedin/failure'
callback = "${baseURL}/oauth/linkedin/callback"
}
// for Google OAuth 2.0
google {
api = org.grails.plugin.springsecurity.oauth.GoogleApi20
key = 'oauth_google_key'
secret = 'oauth_google_secret'
successUri = '/oauth/google/success'
failureUri = '/oauth/google/failure'
callback = "${baseURL}/oauth/google/callback"
scope = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'
}
}
}
grails.plugin.springsecurity.controllerAnnotations.staticRules = [
....
'/oauth': ['permitAll'],
....
]
User.groovy 에 다음을 추가한다.
static hasMany = [oAuthIDs: OAuthID]
Google Developers Console 프로젝트 생성
https://console.developers.google.com/project
grils oauth Q&A
문제
compile ":spring-security-oauth-google:0.3.1" 적용하는데 아래와 같은 오류가 나요
Error |
Resolve error obtaining dependencies: Could not find artifact org.scribe:scribe:jar:1.3.6 in grailsCentral (http://repo.grails.org/grails/plugins) (Use --stacktrace to see the full trace)
해결
repositories 에 다음을 추가해주세요
mavenRepo "https://raw.github.com/fernandezpablo85/scribe-java/mvn-repo"
문제
s2-init-oauth com.shuiky.anything OAuthID 실행하면 다음과 같은 오류 발생
java.lang.NullPointerException: Cannot invoke method lastIndexOf() on null object
Error |
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Error |
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
Error |
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
Error |
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
해결
조금 이따 또는 GGTS를 종료 후 다시 시작하니 잘 됨......ㅡㅡ;; 모지
spring-security-oauth-google-0.3.1 의 dependencies
spring-security-oauth-2.1.0-RC4
spring-security-core-2.0-RC3
oauth-2.5
codenarc-0.21
설정
https://github.com/cazacugmihai/grails-spring-security-oauth
구글 oauth 범위
https://developers.google.com/+/api/oauth?hl=ko
oauth 개념
https://developers.google.com/gdata/articles/oauth
http://www.slideshare.net/SpringCentral/so2gx-building-apiswithgrails
샘플
https://github.com/TouK/grails-oauth-scribe-example