Shiro-Oauth插件

时间:2014-01-15 02:19:26

标签: grails oauth shiro

我正在尝试使用Shiro-Oauth 0.3插件进行以下设置。 配置:

oauth {
    providers {
        google {
            api = org.scribe.builder.api.GoogleApi
            key = 'key'
            secret = 'secret'
            scope = 'https://www.googleapis.com/auth/userinfo.email'
            callback = "${grails.serverURL}/oauth/google/callback"
            successUri = '/oauth/success?provider=google'
            failureUri = '/oauth/failure'
        }
    }
    debug = true
}

security.shiro.oauth.linkAccountUrl = "/oauth/linkaccount"

构建配置:

repositories {
    mavenRepo "http://repo.desirableobjects.co.uk/"
}

plugins {
    compile (":shiro:1.2.0") {
        excludes "servlet-api"
    }

    compile ":shiro-oauth:0.3"
}

当我运行项目时,我得到以下内容:

配置Shiro ...

| Error 2014-01-14 17:49:04,233 [localhost-startStop-1] ERROR context.GrailsContextLoader  -         Error initializing the application: Error creating bean with name 'uk.co.desirableobjects.oauth.scribe.OauthController': Initialization of bean failed; nested   exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauthService': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class   [uk.co.desirableobjects.oauth.scribe.OauthService]: Constructor threw exception; nested exception  is java.lang.IllegalArgumentException: Callback must be a valid URL or 'oob'
Message: Error creating bean with name 'uk.co.desirableobjects.oauth.scribe.OauthController': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauthService': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class  [uk.co.desirableobjects.oauth.scribe.OauthService]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Callback must be a valid URL or 'oob'
   Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run      in     ''
^   695 | run . .  in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'oauthService': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [uk.co.desirableobjects.oauth.scribe.OauthService]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Callback must be a valid URL or 'oob'
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run      in     ''
^   695 | run . .  in java.lang.Thread
Caused by BeanInstantiationException: Could not instantiate bean class     [uk.co.desirableobjects.oauth.scribe.OauthService]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Callback must be a valid URL or 'oob'
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   138 | run      in java.util.concurrent.FutureTask
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run      in     ''
^   695 | run . .  in java.lang.Thread
Caused by IllegalArgumentException: Callback must be a valid URL or 'oob'
->>  80 | check    in org.scribe.utils.Preconditions
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    66 | checkValidOAuthCallback in     ''
|    87 | callback in org.scribe.builder.ServiceBuilder
|    84 | doCall   in uk.co.desirableobjects.oauth.scribe.OauthService$_buildService_closure1
|    66 | buildService in uk.co.desirableobjects.oauth.scribe.OauthService
|    43 | <init>   in     ''
|   303 | innerRun in java.util.concurrent.FutureTask$Sync
|   138 | run      in java.util.concurrent.FutureTask
|   895 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run      in     ''
^   695 | run . .  in java.lang.Thread
| Error Forked Grails VM exited with error

有人提出为什么会这样做的任何想法?

2 个答案:

答案 0 :(得分:0)

grails.serverURL中是否设置了Config.groovy? OAuth提供程序将回调您的服务器,因此您必须配置正确的URL。

答案 1 :(得分:-1)

当您未正确配置serverUrl时会发生这种情况,从而导致无效的oauth回调网址。

在config.groovy

中试试
environments {
production {
      grails.serverUrl = "http://your domain name"
    }

    development {
     grails.serverURL = "http://localhost:8080/your app"
    } 
}

这应该可以解决错误