5 Upgrading from grails-oauth - Reference Documentation
Authors: Antony Jones, Peter Ledbrook
Version: 2.2.1
5 Upgrading from grails-oauth
grails-oauth vesion 2.x is a ground-up rewrite of the previous plugin (< 1.x), with a number of small differences in its set-up.This quick guide will attempt to make the transition as seamless as possible.Configuration
The configuration block's structure remains mainly the same, with the important changes documented belowOld Configuration Directive | New Configuration Directive |
---|---|
requestTokenUrl | Replaced with 'api' directive, see 3. Further Configuration |
accessTokenUrl | Replaced with 'api' directive, see 3. Further Configuration |
authUrl | Replaced with 'api' directive, see 3. Further Configuration |
consumer.key | key |
consumer.secret | secret |
The plugin does not currently support multiple consumers, it is recommended to set up multiple providers with different names if you need this functionality.
In the view layer (GSP)
The oauth link tag has become much more simplified:<g:oauthLink consumer='myConsumer'
returnTo="[controller: 'myController', action: 'oauthComplete']">Authorize</g:oauthLink>
<oauth:connect provider="myConsumer">Authorize</oauth:connect>
The 'returnTo' directive above has been moved into your configuration as 'successUri' and 'failureUri'. See 3. Further Configuration for further details.
Accessing oauth protected resources
Accessing resources is now done via convention rather than configuration, so the following block of codedef response = oauthService.accessResource(url: 'http://api.url', consumer: 'twitter', token:[key: 'accesskey', secret: 'accesssecret'], method: 'POST')
def response = oauthService.postTwitterResource(twitterAccessToken, 'http://api.url')
org.scribe.model.Token
and the second parameter is the url of the oauth protected resource you are trying to access.