【问题标题】:Spring security Oauth2 client ClientAuthenticationProcessingFilterSpring security Oauth2 客户端 ClientAuthenticationProcessingFilter
【发布时间】:2013-06-20 04:48:39
【问题描述】:

我正在开发 spring-security-oauth2-1.0.3.RELEASE,试图设置一个 oauth 客户端来让用户通过 google 进行身份验证。

我在这方面花了一段时间,但仍然没有找到太多解释清楚的好文章。

我正在做的是像这样将 OAuth2ClientAuthenticationProcessingFilter 放入过滤器链中:

<http xmlns="http://www.springframework.org/schema/security"
    use-expressions="true" pattern="/oauth.html" auto-config="true">
    <sec:intercept-url pattern="/**" access="isFullyAuthenticated()" />
    <custom-filter ref="oauth2ClientFilter" position="CAS_FILTER" />
    <sec:custom-filter ref="googleAuthFilter" after="CAS_FILTER" />
</http>

自定义过滤器:googleAuthFilter 可以保护我的 URL。

阅读OAuth2ClientAuthenticationProcessingFilter的源码,需要参考

  1. 一个 OAuth2RestOperations(rest 模板),它引用一个 Oauth 服务器资源(关于 google 的信息)
  2. ResourceServerTokenServices(来自 Spring-security-oauth 库提供程序包)。

现在我很困惑。 Spring-security-oauth分为2部分:client和provider。

由于我只是设置一个 Oauth 客户端,为什么我需要从 Oauth 提供程序包中获得一个类的引用?

另外,我应该如何设置 ResourceServerTokenServices?现在我正在尝试使用默认实现。因为 DefaultTokenServices 再次需要引用

  1. 令牌存储
  2. ClientDetailsS​​ervice
  3. 令牌增强器

到目前为止,我尝试了所有默认实现:

  • TokenStore: InMemoryTokenStore
  • ClientDetailsS​​ervice:InMemoryClientDetailsS​​ervice
  • TokenEnhancer:TokenEnhancerChain

它似乎不起作用......

谢谢!

【问题讨论】:

  • 您找到解决方案了吗?

标签: spring-security oauth-2.0 google-oauth oauth2client


【解决方案1】:

我想我可以写点什么。但是您使用的版本很旧,Spring Security OAuth2 的最新版本非常易于使用并且应用广泛 - 许多文档。让我们搜索一下:D

http://jhasaket.blogspot.com/2014/09/securing-spring-mvc-application-using.html

【讨论】:

    【解决方案2】:

    查看 Spring“社交客户端”教程,

    https://spring.io/guides/tutorials/spring-boot-oauth2/#_social_login_github

    该教程包含 Facebook 和 Gist 的信息。我想不通的一个部分 - userInfo URL - 我最终不是在 Google 上发现的,而是在此处显示的 .YML 文件数据中发现的:

    http://www.techforumist.com/google-oauth2-login-in-spring-boot-and-angularjs/

    在本地复制(本着 SO 实践的精神,提供的不仅仅是 URL :-)):

    oauth2:
        client:
          clientId: <Client ID from google developer console>
          clientSecret: <Client Secret from google developer console>
          accessTokenUri: https://www.googleapis.com/oauth2/v4/token
          userAuthorizationUri: https://accounts.google.com/o/oauth2/v2/auth
          clientAuthenticationScheme: form
          scope:
            - openid
            - email
            - profile
        resource:
          userInfoUri: https://www.googleapis.com/oauth2/v3/userinfo
          preferTokenInfo: true
    

    希望这对您有所帮助(我花了一段时间才找到所有这些)!

    附注我有一个应用程序使用 Spring Boot OAuth2 安全性成功地针对 Google 进行身份验证 - 不要放弃希望!我目前缺少的是一种方法来解压我返回的数据以确定用户的 Google 电子邮件地址以列入白名单 - 请参阅下面的 SO 链接:

    How to get google user email to whitelist users when authenticating using Spring Boot OAuth2 against Google

    【讨论】:

      猜你喜欢
      • 2012-10-22
      • 2019-04-06
      • 2017-09-17
      • 2020-02-11
      • 2021-03-07
      • 2022-11-08
      • 1970-01-01
      • 2019-07-20
      • 2015-11-05
      相关资源
      最近更新 更多