OAuth2入门

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值