Skip to content

认证授权

更新: 2/10/2025 字数: 0 字 时长: 0 分钟

目的

  • 1、支持系统账密登录。
  • 2、支持邮箱登录。
  • 3、支持短信登录。
  • 4、支持微信登录(OpenId)。
  • 5、支持企业微信登录。
  • 6、支持Github、Gitee登录。
  • 7、支持第三方授权登录。

相关地址

认证流程


授权模式

授权码模式

客户端凭证模式

令牌刷新模式

密码模式

Api调用

http
###### 获取授权码
# client_id 客户端ID
# response_type 响应模式
# scope 授权范围(不清楚可以百度一下)
# redirect_uri 回调地址,code会通过这个地址返回

GET http://127.0.0.1:8084/oauth2/authorize?client_id=sas-client&response_type=code&scope=message.read+openid&redirect_uri=http://127.0.0.1:8084/test
Authorization: Basic c2FzLWNsaWVudDpzYXMtc2VjcmV0

### 使用授权码token
# grant_type 授权模式
# code 你的授权码
# redirect_uri 回调地址,请求code时所传参数

POST http://127.0.0.1:8084/oauth2/token
Content-Type: application/x-www-form-urlencoded
Authorization: Basic c2FzLWNsaWVudDpzYXMtc2VjcmV0

grant_type = authorization_code &
code = {code} &
redirect_uri = http://127.0.0.1:8084/test

###### 账号密码获取token
# grant_type 授权模式
# username 账号
# password 密码
# scope 授权范围(不清楚可以百度一下)

POST http://127.0.0.1:8084/oauth2/token
Content-Type: application/x-www-form-urlencoded
Authorization: Basic c2FzLWNsaWVudDpzYXMtc2VjcmV0

grant_type = password &
username = {username} &
password = {password}

###### 客户端获取token
# grant_type 授权模式

POST http://127.0.0.1:8084/oauth2/token
Content-Type: application/x-www-form-urlencoded
Authorization: Basic c2FzLWNsaWVudDpzYXMtc2VjcmV0

grant_type = client_credentials

###### 刷新token
# grant_type 授权模式
# refresh_token refresh_token

POST http://127.0.0.1:8084/oauth2/token
Content-Type: application/x-www-form-urlencoded
Authorization: Basic c2FzLWNsaWVudDpzYXMtc2VjcmV0

grant_type = refresh_token &
refresh_token = {refresh_token}

验证码

java
// 验证码流程:生成 -> 存储 -> 发送 -> 校验 -> 删除
// 存储:
// 验证:
// 类型: