OAuth2入门

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

1.下载资源

演示代码

 克隆下载到本地

 导入项目

        

client    客户
authorization-server    认证服务
resource-owner     资源所有者
resource-server    资源服务器

流程
客户向资源所有者申请授权码
资源所有者下发授权码
客户拿到授权码后向认证服务器申请令牌
认证服务器接到申请下方令牌
客户获取令牌后向资源服务器请求数据

 2.必须配置的资源

<dependencies>
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
application.yml
spring:
application:
name: OAuth2-client
server:
port: 8080

认证服务器

pom.xml
<dependencies>
<dependency>
<groupId> org.apache.oltu.oauth2 </groupId>
<artifactId> org.apache.oltu.oauth2.authzserver </artifactId>
</dependency>
<dependency>
<groupId> org.apache.oltu.oauth2 </groupId>
<artifactId> org.apache.oltu.oauth2.resourceserver </artifactId>
</dependency>
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-starter-web </artifactId>
</dependency>
<dependency>
<groupId> org.projectlombok </groupId>
<artifactId> lombok </artifactId>
<optional> true </optional>
</dependency>
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-starter-test </artifactId>
<scope> test </scope>
</dependency>
</dependencies>
application.yml
spring:
application:
name: OAuth2-authorization-server
server:
port: 8081

资源拥有者

 

<dependencies>
<dependency>
<groupId> org.apache.oltu.oauth2 </groupId>
<artifactId> org.apache.oltu.oauth2.authzserver </artifactId>
</dependency>
<dependency>
<groupId> org.apache.oltu.oauth2 </groupId>
<artifactId> org.apache.oltu.oauth2.resourceserver </artifactId>
</dependency>
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-starter-web </artifactId>
</dependency>
<dependency>
<groupId> org.projectlombok </groupId>
<artifactId> lombok </artifactId>
<optional> true </optional>
</dependency>
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-starter-test </artifactId>
<scope> test </scope>
</dependency>
</dependencies>

application.yml

 

spring :
application :
name : OAuth2-resource-owner
server :
port : 8082

资源服务器

 

pom.xml
<dependencies>
<dependency>
<groupId> org.apache.oltu.oauth2 </groupId>
<artifactId> org.apache.oltu.oauth2.authzserver </artifactId>
</dependency>
<dependency>
<groupId> org.apache.oltu.oauth2 </groupId>
<artifactId> org.apache.oltu.oauth2.resourceserver </artifactId>
</dependency>
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-starter-web </artifactId>
</dependency>
<dependency>
<groupId> org.projectlombok </groupId>
<artifactId> lombok </artifactId>
<optional> true </optional>
</dependency>
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-starter-test </artifactId>
<scope> test </scope>
</dependency>
</dependencies>
application.yml
spring :
application :
name : oauth2-resource-server
server :
port : 8083
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6