# spring-cloud-starter-oauth2-demo **Repository Path**: mx-sky/spring-cloud-starter-oauth2-demo ## Basic Information - **Project Name**: spring-cloud-starter-oauth2-demo - **Description**: 基于spring-cloud-starter-oauth2搭建的一个demo - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-12-21 - **Last Updated**: 2022-06-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # spring-cloud-starter-oauth2-demo #### 介绍 基于spring-cloud-starter-oauth2搭建的一个demo #### 依赖版本 spring cloud Greenwich.SR3 jdk8 spring boot 2.1.13.RELEASE ### 四种授权模式 #### 授权码模式 1. 请求授权 ```shell http://localhost:8001/oauth/authorize?response_type=code&client_id=wx-client&redirect_uri=http://www.baidu.com ``` 2. 登录 ![login.jpg](image/login.jpg) 3. 授权 ![approval.jpg](image/approval.jpg) 4. 根据授权码获取token(grant_type=authorization_code) ![code.jpg](image/code.jpg) ```shell http://localhost:8001/oauth/token?client_id=wx-client&client_secret=123456&grant_type=authorization_code&code=hBF7mR&redirect_uri=http://www.baidu.com ``` ![token1.jpg](image/token1.jpg) #### 隐式授权模式 注意:response_type=token 1. 请求授权 ```shell http://localhost:8001/oauth/authorize?response_type=token&client_id=wx-client&redirect_uri=http://www.baidu.com ``` 2. 授权后直接返回token ![token2.jpg](image/token2.jpg) #### 密码模式 根据账号密码直接获取token(grant_type=password) ```shell http://localhost:8001/oauth/token?grant_type=password&username=wx&password=123456&client_id=wx-client&client_secret=123456 ``` ![token3.jpg](image/token3.jpg) #### 客户端模式 根据client_id和client_secret获取token(grant_type=client_credentials) ```shell http://localhost:8001/oauth/token?grant_type=client_credentials&client_id=wx-client&client_secret=123456 ``` ![token4.jpg](image/token4.jpg) ### token校验 `http://localhost:8001/oauth/check_token?token=需要校验的token` 需要带client_id和client_secret ![verify_token.jpg](image/verify_token.jpg) ### 资源服务 不带token ![test1.jpg](image/test1.jpg) 带token ![test2.jpg](image/test2.jpg)