看这篇之前,相信你对SpringBoot,Spring Security,OAuth2都有个大概的了解,什么?不了解?篇幅太长,本人太懒,木有关系,已经替你找好博客了,springBoot介绍,Oauth2 0.0介绍,弹簧安全介绍
如果你是第一次接触,估计看完上面介绍还有有点懵,建议还是多了解一下,其实OAuth2.0的的就是一个协议,了解下它的运行原理,按照协议写代码就好了,OK,了解之后,开工
Spring Security OAuth2
1.导入jar包
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
2.建立数据表,主要存储认证信息以及令牌
表说明文档http://andaily.com/spring-oauth-server/db_table_description.html
create table oauth_client_details (
client_id VARCHAR(256) PRIMARY KEY,
resource_ids VARCHAR(256),
client_secret VARCHAR(256),
scope VARCHAR(256),
authorized_grant_types VARCHAR(256),
web_server_redirect_uri VARCHAR(256),
authorities VARCHAR(256),
access_token_validity INTEGER,
refresh_token_validity INTEGER,
additional_information VARCHAR(4096),
autoapprove VARCHAR(256)
);
create table oauth_client_token (
to