前言
要解决的问题:不暴露客户密码的情况下授权三方服务访问客户资源
角色:资源拥有者,客户端应用(三方服务),授权服务器,资源服务器
模式:授权码模式:需要客户授权得到授权码后再次通过三方服务的密码取得token,双重校验,最安全,最复杂
简易模式:无需授权码对用户暴露返回的Token,不安全
密码模式:客户端应用需要资源拥有者密码。全链路可信情况下使用
客户端模式:无需资源拥有者密码,只需要客户端应用密码进行校验,服务器对服务器使用
本试验主要演示注册码模式,分为授权服务器和资源服务器俩个应用,后续会持续扩展为单个授权服务器和多个资源服务器。
试验步骤
按照以下截图创建授权服务器,授权服务器包结构如下
1 使用pom文件导入相应依赖,主要导入了以下依赖包
1)SpringBoot的security和web,
2)SpringSecurity的OAuth2
pom文件如下
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>io.spring2go</groupId> <artifactId>authcode-server</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>authcode-server</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <properties