0

我正在使用带有 Oauth2 安全性的 Spring Boot 应用程序

我已将 ClientDetailsS​​erviceConfigurer 配置为使用client01客户端仅向具有ROLE_USER的用户颁发令牌,如下所示:

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
            clients.inMemory()
                    .withClient("client01")
                    .scopes("read", "write")
                    .authorities("ROLE_USER")
                    .authorizedGrantTypes("password", "refresh_token")
                    .secret("password")
                    .accessTokenValiditySeconds(1800);
}

curl  -X POST -vu client01:password 'http://localhost:8080/api/oauth/token?username=admin01&password=test&grant_type=password'

为什么使用这个客户端我也可以使用ROLE_ADMIN向用户发放令牌?

如果我有错误的实现,那什么是正确的?

我的目标是创建两个客户端: - 一个客户端应该只允许使用 ROLE_ADMIN 对用户进行身份验证;- 另一个客户端应该只允许使用 ROLE_USER 对用户进行身份验证;

4

0 回答 0