使用 Spring 安全 Rest 插件时收到来自 GitHub 的弃用警告

Receiving deprecation warnings from GitHub when using the Spring Security Rest Plugin

我有一个使用 spring-security-rest 插件版本 2.0.0.RC1 的 Grails 3 应用程序,使用 GitHub 进行用户身份验证。

我看到来自 GitHub 的警告:

Your application used an access token as part of a query parameter to access an endpoint through the GitHub API:
    https://api.github.com/user
Please use the Authorization HTTP header instead as using the `access_token` query parameter is deprecated.

是否有修复此问题且仍适用于 Grails 3 的版本?

我认为弃用警告会在 2020 年 11 月失效。

更新: 探索 pac4j 我在 OAuthConfiguration class 中看到有一个 tokenAsHeader 变量。如果设置,它会在获取用户信息时将授权令牌添加到 header。

我不确定这是否可行,但我将 tokenAsHeader = true 添加到 application.groovy:

github {
  client = org.pac4j.oauth.client.GitHubClient 
  key = '${APP_KEY}' 
  secret = '${APP_SECRET}' 
  scope = 'user' 
  tokenAsHeader = true
  defaultRoles = ['ROLE_GITHUB'] 
}

我没有看到调试输出有任何变化,而且我只是定期收到已弃用的警告电子邮件,所以我不确定这是否是一个解决方案。

如您所知,OAuth 客户端不是 Spring Security REST 本身的一部分,而是来自 Pac4j。 Spring 安全 REST 2.0.0.RC1 随 Pac4j 2.2.1 一起发布,该版本已有 2.5 年历史。因此,当时客户端的有效设置现在可能已被弃用。

你的机会是:

  1. 在本地升级到较新的 Pac4j 版本。它应该可以顺利升级到 4.0.0。在 build.gradle:

    compile("org.grails.plugins:spring-security-rest:2.0.0.RC1") {
        exclude group: 'org.pac4j'
    }
    compile "org.pac4j:pac4j-core:3.8.3"
    compile "org.pac4j:pac4j-oauth:3.8.3"
    
  2. 将您的应用程序升级到 Grails 4 并使用 Spring Security REST 3.0.1,它使用 pac4j 3.8.3