SpringSecurityOauth2的授权服务器也支持通过yaml配置文件来配置,不过其token的存储方式只能是基于内存和JWT方式。无需你编写授权服务器配置类。
@EnableAuthorizationServer
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
只需要以上方式加上SpringSecurity的一个配置类就可以。<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/1609516/1628513913910-988c92ca-ad90-4897-aa21-f845821249fe.png#clientId=uc1548e8f-6f6a-4&from=paste&height=326&id=ud5fb68ac&margin=%5Bobject%20Object%5D&name=image.png&originHeight=326&originWidth=427&originalType=binary&ratio=1&size=17813&status=done&style=none&taskId=u48ca11e6-994b-4010-865f-17e85c6ccdc&width=427)<br />最后展示一下Yaml的配置:
security:
oauth2:
client:
client-id: gaoxi
client-secret: "123456"
access-token-uri: http://www.baidu.com
scope: read,write
authorized-grant-types: client_credentials,password,refresh_token
authorization:
token-key-access: permitAll()
check-token-access: permitAll()
jwt:
key-value: 123456
这样就可以使用了。