【问题标题】:Spring Boot Oauth2 use multiple grant_types for for same URLSpring Boot Oauth2 对同一个 URL 使用多个 grant_types
【发布时间】:2018-10-28 11:58:39
【问题描述】:

是否可以将 Spring Boot 配置为允许 Oauth2 在同一 URL 上授予类型 passwordauthorization_code。例如/boot

我已经完成了基本的授权配置如下

security:
  oauth2:
    client:
      accessTokenUri: http://UAA/oauth/token
      userAuthorizationUri: http://UAA/oauth/authorize
      clientId: ******
      clientSecret: ******
    resource:
      userInfoUri: http://UAA/userinfo

但是,所有受此配置保护的端点都使用表单登录并重定向到 UAA 授权 URL,即使请求是使用 Authorization Bearer **** 令牌标头发送的。这意味着即使我在邮递员中发送 Authorization 令牌,我也会收到 HTTP Status 302 以及 UAA 登录页面的 HTML 响应。

【问题讨论】:

    标签: java spring spring-security spring-oauth2


    【解决方案1】:

    您可以配置授权服务器来创建 OAuth 客户端,而不是在配置文件中进行配置。然后,您可以为客户端配置多种授权类型、权限、范围等...

       @Override
            public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
                clients.inMemory().withClient("client_id").authorizedGrantTypes("password", "client_credentials")
                        .secret("secret").authorities("Authority1", "Authority2").scopes("READ", "WRITE").resourceIds("resource_server_id");
        }
    

    详情请查看This Spring OAuth sample

    【讨论】:

      猜你喜欢
      • 2018-10-08
      • 2021-05-07
      • 1970-01-01
      • 2016-11-08
      • 2018-01-05
      • 1970-01-01
      • 2019-05-15
      • 2017-03-14
      • 2019-02-05
      相关资源
      最近更新 更多