簡體   English   中英

我的 OAuth 2 資源服務器的多個身份驗證服務器

[英]Multiple authentication servers for my OAuth 2 resource server

我已經使用 Spring Boot 和 Spring Oauth2 實現了一個簡單的資源服務器,並使用 Google 作為身份驗證服務器:

spring:
  security:
    oauth2:
      client:
        registration:
          google:
            client-id: clientId
            client-secret: clientSecret
            scope: openid,profile,email
      resourceserver:
        jwt:
          issuer-uri: https://accounts.google.com
          jwk-set-uri: https://www.googleapis.com/oauth2/v3/certs
@RestController
public class Controller {

    @GetMapping("/hi")
    public String hello() {
        return "hello";
    }
}
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(final HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/**").fullyAuthenticated()
                .and()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .oauth2ResourceServer().jwt()
                .and()
                .and()
                .cors().and().csrf().disable();

    }

}

如何添加更多的身份驗證服務器,例如 Github、Facebook 或 Twitter?

現在我可以生成 id_token 和 access_token 用於 Google 身份驗證,但我不確定 Github 或 Facebook 是否支持它。 我在他們的文檔中找不到類似的東西。

最后,我想要 3 個身份驗證提供程序,我將能夠生成 id_token 並將其作為 Postman 中的身份驗證標頭發送。 我什至無法為 Github 找到jwk-set-uriissuer-uri ,以用 Github 替換 Google 身份驗證服務器。

對於多租戶場景(多個令牌發行者),您應該查看https://github.com/ch4mpy/spring-addons 您的用例非常接近https://github.com/ch4mpy/spring-addons/tree/master/samples/tutorials/resource-server_with_oauthentication

Spring Boot 團隊決定不支持多個令牌頒發者: https ://github.com/spring-projects/spring-boot/issues/30108#issuecomment-1163292478

關於 Github 和 OpenID: 什么是 GitHub /.well-known/openid-configuration URL? . 您仍然可以按照Github doc將其用作 OAuth2 提供程序,但 Github 作為 access-token 生成的是不透明的令牌(不是 JWT)。 要檢查令牌是否有效(由 github 頒發、未過期、未撤銷……)並獲取有關經過身份驗證的用戶的信息,您必須向 Github API 發出請求,這是非常有限的。 您可以使用 OpenID 授權服務器(如 Keycloak)作為身份代理,這將

  • 使用 Github(和其他)作為身份提供者
  • 為您的客戶提供 JWT 訪問令牌(Postman、Web 應用程序、本機移動應用程序等)
  • 也許集中用戶角色管理

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM