Spring boot SpringBoot OAuth2:secret()函数的用途?
我目前正在学习SpringBoots OAuth2.0的实现,我遇到了以下教程: 它包含以下代码:Spring boot SpringBoot OAuth2:secret()函数的用途?,spring-boot,oauth-2.0,Spring Boot,Oauth 2.0,我目前正在学习SpringBoots OAuth2.0的实现,我遇到了以下教程: 它包含以下代码: @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { clients.inMemory() .withClient("trusted-app") .authorizedGrantTypes("client_credent
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("trusted-app")
.authorizedGrantTypes("client_credentials", "password", "refresh_token")
.authorities("ROLE_TRUSTED_CLIENT")
.scopes("read", "write")
.resourceIds(resourceId)
.accessTokenValiditySeconds(accessTokenValiditySeconds)
.refreshTokenValiditySeconds(refreshTokenValiditySeconds)
.secret("secret");
}
我在互联网上到处寻找secret
函数的文档,但我根本找不到它的功能,包括官方的SpringBoot API参考。我可以肯定地说,它需要一个字符串
参数
secret()
函数在上面的代码段中到底做了什么?SpringBoot如何处理此函数的参数?secret()
实际上代表的是客户机密钥。当您要发布令牌时,您的请求应该由服务器授权。因此,client\u id
和client\u secret
用于授权。在您的http
请求中,您应该在http
标题中发送client\u id
和client\u secret
(可能是base64格式)。它被称为基本授权。对于身份验证,您需要发送用户名和密码
可能您应该在http
标题中发送类似的内容(基本:base64
您的client\u id
和client\u secret
)的值)
如果您使用的是邮递员,那么您的令牌端点将http://host:port/contextPath/oauth/token
并请求牧民
如果单击“标题”选项卡,您将看到您的客户机id
和机密
是如何以base64
格式转换的。在请求正文中,您应该将令牌作为键值对发送授权类型
:密码
。您还应该向stackoverflow的其他用户上传答案。;)
"Authorization":"Basic dHJ1c3RlZC1hcHA6c2VjcmV0"