【问题标题】:spring security oauth2 client_credentials flow onlyspring security oauth2 client_credentials 仅流程
【发布时间】:2015-11-27 07:13:49
【问题描述】:

我正在尝试使用 Spring Boot 创建仅支持客户端凭据流的 oauth2 授权。据我了解,客户端直接访问 /oauth/token 端点。有没有办法在 Spring Boot 中禁用 /oauth/authorize 端点并允许直接访问 /oauth/token 而无需先获得完全授权?

@Configuration
@EnableAuthorizationServer
public class OAuth2Configuration extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private AuthenticationManager authenticationManager;

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        // TODO: Is there something I can do here to disable /oauth/authorize?
        endpoints.authenticationManager(authenticationManager);
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        // client details configuration
    }

}

【问题讨论】:

    标签: java spring oauth spring-security spring-boot


    【解决方案1】:

    我不能说禁用授权端点,但您是对的,您可以使用客户端凭据流直接进入令牌端点。我可能在重申您已经知道的内容,但是“客户端”的凭据(client_id/client_secret)与“用户”的凭据(用户名/密码)不同。 “用户”转到授权端点,以便客户端可以从令牌端点获取令牌。 “客户端”(在客户端凭据流中)直接将客户端凭据提供给令牌端点。是否需要禁用授权端点?

    因此,对于 client_credentials 流程,您无需先去授权(您无需禁用它)。如果您的 spring-boot 授权服务器位于 localhost:8080 上,以下是您如何卷曲您的令牌:

    curl -H "授权:基本 d2VhcHA6" -X POST http://localhost:8080/oauth/token?grant_type=client_credentials

    其中 d2VhcHA6 是您的“client_id:client_secret”的 base64 编码

    【讨论】:

    • 谢谢。我只是想避免暴露一个不会被使用的端点。但是,它的其余部分适用于 client_credentials。
    猜你喜欢
    • 2020-05-26
    • 2017-03-17
    • 2014-05-10
    • 2017-06-10
    • 2021-05-17
    • 2015-02-08
    • 2019-09-25
    • 2021-12-22
    • 2012-05-27
    相关资源
    最近更新 更多