使用Google OAuth 2.0和使用Yahoo OAuth 1.0进行CAS OAuth身份验证

时间:2013-07-05 17:47:52

标签: oauth google-oauth cas

我已成功配置我的CAS v.3.5.2,使用OAuth 1.0将身份验证委派给Yahoo,方法是遵循https://wiki.jasig.org/display/CASUM/Configuration+for+the+OAuth+client+support+in+CAS+server+version+%3E%3D+3.5.1中的Jasig CAS Wiki说明 现在,我正在尝试使用OAuth 2.0向Google添加身份验证。为此,我使用Google2Provider将scribe-up的依赖关系更新为1.3.1。但是在访问CAS登录页面时会抛出以下错误:

SEVERE: Servlet.service() for servlet [cas] in context with path [/cas] threw exception [Request processing failed; nested exception is org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing org.jasig.cas.support.oauth.web.flow.OAuthAction@4d88f286 in state 'oauthAction' of flow 'login' -- action execution attributes were 'map[[empty]]'] with root cause
java.lang.IllegalArgumentException: Cannot encode null object
at org.scribe.utils.Preconditions.check(Preconditions.java:82)
at org.scribe.utils.Preconditions.checkNotNull(Preconditions.java:29)
at org.scribe.utils.OAuthEncoder.encode(OAuthEncoder.java:28)
at org.scribe.up.addon_to_scribe.GoogleApi20.getAuthorizationUrl(GoogleApi20.java:36)
at org.scribe.oauth.OAuth20ServiceImpl.getAuthorizationUrl(OAuth20ServiceImpl.java:69)
at org.scribe.up.provider.BaseOAuth20Provider.getAuthorizationUrl(BaseOAuth20Provider.java:43)
at org.jasig.cas.support.oauth.web.flow.OAuthAction.doExecute(OAuthAction.java:128)

...

看来异常是由GoogleApi20.getAuthorizationUrl(最终OAuthConfig配置)中config参数的null“范围”引起的,其中config.getScope()返回null:

public String getAuthorizationUrl(final OAuthConfig config) {
    return String.format(AUTHORIZATION_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()),
                         OAuthEncoder.encode(config.getScope()));
} 

通过使用OAuth 1.0与Yahoo进行身份验证以及在CAS中同时使用OAuth 2.0对Google进行身份验证,是否可以实现此目的?有没有一个例子说明如何做到这一点?

提前谢谢。

1 个答案:

答案 0 :(得分:1)

我是CAS中OAuth客户端支持的创建者。事实上, Google2Provider 中存在一个错误:默认范围为空。使用适当的setter设置实际范围:setScope(final Google2Scope scope)以解决问题......