gpt4 book ai didi

java - 如何在Spring OAuth2中仅通过client_id和secret进行授权?

转载 作者:行者123 更新时间:2023-11-30 02:14:58 26 4
gpt4 key购买 nike

现在我正在使用下一个配置:

@Configuration
@EnableAuthorizationServer
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class OAuth2Config extends AuthorizationServerConfigurerAdapter {

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.jdbc(mAppConfig.dataSource())
.withClient("virto")
.secret("secret")
.authorizedGrantTypes("password", "authorization_code", "refresh_token");
}
}

它需要发送client_id、client_secret、用户名、密码...但我需要为具有client_id的可信服务器提供access_token > 和 client_secret 而已...我怎样才能做到呢?可能吗?

最佳答案

您需要使用 client_credentials grant 配置客户端

@Configuration
@EnableAuthorizationServer
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class OAuth2Config extends AuthorizationServerConfigurerAdapter {

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.jdbc(mAppConfig.dataSource())
.withClient("virto")
.secret("secret")
.authorizedGrantTypes("client_credentials");
}
}

要获取 token ,您需要发送一个 POST 请求,并使用 Base 64 编码的凭据。

POST http://localhost:8080/paymentiq/oauth/token?grant_type=client_credentials -h 'Authorization: [clientId:secret]'

关于java - 如何在Spring OAuth2中仅通过client_id和secret进行授权?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48868789/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com