Skip to content

Instantly share code, notes, and snippets.

@pjagielski
Created April 10, 2012 15:44
Show Gist options
  • Save pjagielski/2352284 to your computer and use it in GitHub Desktop.
Save pjagielski/2352284 to your computer and use it in GitHub Desktop.
GoogleAuthService
class GoogleAuthService extends GrailsOAuthService {
@Override
OAuthService createOAuthService(String callbackUrl) {
def builder = createServiceBuilder(GoogleApi20,
grailsApplication.config.auth.google.key as String,
grailsApplication.config.auth.google.secret as String,
callbackUrl)
return builder.grantType(OAuthConstants.AUTHORIZATION_CODE)
.scope('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email')
.build()
}
AuthInfo getAuthInfo(String callbackUrl) {
OAuthService authService = createOAuthService(callbackUrl)
new AuthInfo(authUrl: authService.getAuthorizationUrl(null), service: authService)
}
Token getAccessToken(OAuthService authService, Map params, Token requestToken) {
Verifier verifier = new Verifier(params.code)
authService.getAccessToken(requestToken, verifier)
}
}
public abstract class GrailsOAuthService {
static transactional = false
OAuthService oauthService
def grailsApplication
@Override
ServiceBuilder createServiceBuilder(Class provider, String apiKey, String secretKey, String callbackUrl) {
def ServiceBuilder builder = new ServiceBuilder().provider(provider)
.apiKey(apiKey).apiSecret(secretKey)
.callback(callbackUrl)
return builder
}
abstract AuthInfo getAuthInfo(String callbackUrl)
abstract Token getAccessToken(OAuthService authService, Map params, Token requestToken)
abstract OAuthProfile getProfile(OAuthService authService, Token accessToken)
}
class AuthInfo {
OAuthService service
String authUrl
Token requestToken
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment