【问题标题】:CAS OAuth Authentication Using Google OAuth 2.0 and Using Yahoo OAuth 1.0CAS OAuth 身份验证使用 Google OAuth 2.0 和使用 Yahoo OAuth 1.0
【发布时间】:2013-12-31 06:54:58
【问题描述】:

按照 Jasig CAS Wiki https://wiki.jasig.org/display/CASUM/Configuration+for+the+OAuth+client+support+in+CAS+server+version+%3E%3D+3.5.1 的说明,我已成功配置我的 CAS v. 3.5.2 以使用 OAuth 1.0 将身份验证委托给 Yahoo 现在,我正在尝试使用 OAuth 2.0 添加与 Google 的身份验证。为此,我通过将 scribe-up 的依赖更新到 1.3.1 来使用 Google2Provider。但是访问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(final OAuthConfig config) 中的 config 参数的“范围”为空引起的,其中 config.getScope() 返回 null:

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

那么,是否可以通过在 CAS 中同时使用 OAuth 1.0 向 Yahoo 进行身份验证和使用 OAuth 2.0 向 Google 进行身份验证来实现此功能?有没有例子说明这是如何做到的?

提前谢谢你。

【问题讨论】:

    标签: oauth google-oauth cas


    【解决方案1】:

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

    【讨论】:

    • 啊,正如我在调试一天后所怀疑的那样。谢谢杰罗姆的确认!由于此错误阻止加载 CAS 登录视图,您建议我在哪里调用具有真实范围的 setScope?顺便说一句,我已经尝试将它注入到 google bean 定义中的 applicationContext.xml 中,例如 " ..." 但是没有任何成功。谢谢。
    • 在仔细研究了源代码之后,知道了在哪里设置真正的范围。我要试一试。
    • 类似 应该可以工作...
    猜你喜欢
    • 2012-11-27
    • 2012-05-29
    • 2023-03-05
    • 1970-01-01
    • 2014-05-03
    • 2012-09-17
    • 2012-11-08
    • 1970-01-01
    • 2018-05-02
    相关资源
    最近更新 更多