Created
April 10, 2012 15:44
-
-
Save pjagielski/2352284 to your computer and use it in GitHub Desktop.
GoogleAuthService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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