(Quick Reference)

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 below

Old Configuration DirectiveNew Configuration Directive
requestTokenUrlReplaced with 'api' directive, see 3. Further Configuration
accessTokenUrlReplaced with 'api' directive, see 3. Further Configuration
authUrlReplaced with 'api' directive, see 3. Further Configuration
consumer.keykey
consumer.secretsecret

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>

becomes simply

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

def response = oauthService.accessResource(url: 'http://api.url', consumer: 'twitter',
    token:[key: 'accesskey', secret: 'accesssecret'], method: 'POST')

can be implemented as

def response = oauthService.postTwitterResource(twitterAccessToken, 'http://api.url')

where 'Twitter' is the provider name, twitterAccessToken is an instance of org.scribe.model.Token and the second parameter is the url of the oauth protected resource you are trying to access.