Permalink
Browse files

Fix for oauth2 (Thanks @pledbrook) and upgrade to Scribe 1.3.1 which …

…provides more APIs out-of-the-box.
  • Loading branch information...
1 parent 9b02001 commit b91ac31d7663cd5db9cf214526255f68ec9b8d28 Antony Jones committed Aug 1, 2012
View
@@ -1,6 +1,6 @@
class OauthGrailsPlugin {
- def version = "2.0.2"
+ def version = "2.0.3"
def grailsVersion = "1.3.1 > *"
View
@@ -1,4 +1,4 @@
#Grails Metadata file
-#Fri Apr 27 14:48:44 BST 2012
-app.grails.version=2.0.3
+#Fri Jul 13 00:26:20 BST 2012
+app.grails.version=2.0.4
app.name=grails-oauth
@@ -22,7 +22,7 @@ grails.project.dependency.resolution = {
}
dependencies {
- runtime 'org.scribe:scribe:1.3.0'
+ runtime 'org.scribe:scribe:1.3.1'
test 'org.gmock:gmock:0.8.2',
'org.objenesis:objenesis:1.2'
@@ -7,7 +7,7 @@ import uk.co.desirableobjects.oauth.scribe.exception.MissingRequestTokenExceptio
class OauthController {
- private final Token EMPTY_TOKEN = null
+ private final Token EMPTY_TOKEN = new Token('', '')
OauthService oauthService
@@ -63,7 +63,7 @@ class OauthController {
OauthProvider provider = oauthService.findProviderConfiguration(providerName)
Token requestToken = EMPTY_TOKEN
- if (provider.getOauthVersion() == SupportedOauthVersion.ONE) {
+ if (provider.oauthVersion == SupportedOauthVersion.ONE) {
requestToken = provider.service.requestToken
}
@@ -8,6 +8,7 @@ import grails.test.mixin.TestFor
import spock.lang.Specification
import spock.lang.Shared
import uk.co.desirableobjects.oauth.scribe.exception.MissingRequestTokenException
+import spock.lang.Unroll
@TestFor(OauthController)
class OauthControllerSpec extends Specification {
@@ -119,25 +120,29 @@ class OauthControllerSpec extends Specification {
def 'In Oauth 2, request token endpoint is not hit'() {
+ given:
+ Token emptyToken = controller.EMPTY_TOKEN
+ controller.params.provider = PROVIDER_NAME
+
when:
- controller.params.provider = PROVIDER_NAME
controller.authenticate()
then:
controller.oauthService.findProviderConfiguration(PROVIDER_NAME) >> { return provider }
provider.service.version >> { return '2.0' }
controller.oauthService.findSessionKeyForRequestToken(PROVIDER_NAME) >> { return REQUEST_TOKEN_SESSION_KEY }
- controller.oauthService.getAuthorizationUrl(PROVIDER_NAME, null) >> { return 'http://authorisation.url/auth' }
+ controller.oauthService.getAuthorizationUrl(PROVIDER_NAME, emptyToken) >> { return 'http://authorisation.url/auth' }
and:
- !session[REQUEST_TOKEN_SESSION_KEY]
+ session[REQUEST_TOKEN_SESSION_KEY] == emptyToken
controller.response.redirectUrl == 'http://authorisation.url/auth'
}
- def 'Oauth callback is hit but there is no request token in the session (bad callback domain)'() {
+ @Unroll
+ def 'Oauth callback is hit but there is no request token in the session (bad callback domain) for oauth #oauthVersion'() {
given:
controller.params.provider = PROVIDER_NAME
@@ -150,15 +155,18 @@ class OauthControllerSpec extends Specification {
then:
controller.oauthService.findSessionKeyForRequestToken(PROVIDER_NAME) >> { return REQUEST_TOKEN_SESSION_KEY }
controller.oauthService.findProviderConfiguration(PROVIDER_NAME) >> { return provider }
- provider.service.version >> { return '2.0' }
+ provider.service.version >> { return oauthVersion }
and:
def exception = thrown MissingRequestTokenException
exception.message == "We couldn't find a request token for twitter in the session. A common cause of this is that you have been given a new session by the servlet container because your callback domain is different to the domain you are authenticating from. Check that the domain name in the URL bar of your browser matches the domain name of your callback URL"
+ where:
+ oauthVersion = ['1.0', '2.0']
+
}
- // TODO: {"error":{"message":"Error validating client secret.","type":"OAuthException"}}
+ // TODO: {"error":{"message":"Error validating client secret.","type":"OAuthException"}}
// TODO: Catch and deal with timeouts in a sensible way.
}
@@ -14,6 +14,7 @@ import spock.lang.Unroll
import org.scribe.builder.ServiceBuilder
import org.codehaus.groovy.grails.web.servlet.mvc.exceptions.InvalidUriException
import org.springframework.beans.factory.BeanCreationException
+import grails.test.mixin.TestFor
// This is a horrible hack. To disable automatic mocking and wiring of the
// OauthService bean (because we can't test the configuration handling otherwise)

0 comments on commit b91ac31

Please sign in to comment.