除了认证相关功能外,还提供了/example/demo
、/example/himall
项目,供用户参考如何集成。
- 参考
demo
实例,你可以几分钟之内快速验证如何集成HiAuth; - 参考
himall
实例,你可以快速的启动一个带页面的实例;
- HiAuth Docs:http://docs.hiauth.cn
- HiAuth Admin:http://auth.hiauth.cn/admin
- HiAuth 授权页:http://auth.hiauth.cn
├─cicd 持续集成
├─docs 开发文档
├─example 实例
│ ├─demo 基础实例
│ ├─himall 带有页面的实力
├─hiauth-client-spring-boot-starter 客户端SDK,如果深度的集成,可以参考此SDK,或者直接使用;
├─hiauth-front 管理端前端项目
├─hiauth-server HiAuth服务端
├─hiauth-resource HiAuth资源服务端
├─other 其他内容,数据库脚本等
- 认证中心登录页
- 管理后台登录页
- 超级管理员-用户管理页
- 企业管理员-部门列表页
- 企业管理员-员工列表页
如果你觉得此项目对你有帮助,请给我点个star,谢谢!
- Git
- JDK17+
- Maven 3.8+
$ git clone https://github.com/bestaone/HiAuth.git
# 启动himall实例
$ cd HiAuth/example/himall
$ mvn clean install
$ mvn spring-boot:run
- 访问HiMall:http://127.0.0.1:9000 点击
Login
按钮,登录账号:corpadmin/123456
注意:
127.0.0.1
不能使用localhost
代替,因为数据库中配置了回调地址为http://127.0.0.1:9000
。
authorization_code模式:
-
用户登录并授权后,重定向到
redirect_uri
并附带授权码
(url里的参数code值) -
使用
授权码
换取访问令牌
# 最后的yourCode替换为上面步骤获取的授权码
$ curl --location 'http://auth.hiauth.cn/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Accept: application/json' \
--data 'grant_type=authorization_code&redirect_uri=http%3A%2F%2F127.0.0.1%3A9000%2Flogin%2Foauth2%2Fcode%2Fhiauth-code&client_id=himall&client_secret=secret&code=yourCode'
返回结果:
{
"access_token": "eyJraWQiOiJkZTYxMjVmNi0wYTQ5LTQwMGYtYWMzMC02M2U2Zm",
"refresh_token": "8WS6liiSW0gmUy8yudFAPIHGor3Hf6yBtaBTUNjj3-q9y4JXRlBZ",
"scope": "profile",
"token_type": "Bearer",
"expires_in": 35999
}
client_credentials模式:
$ curl --location 'http://auth.hiauth.cn/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Accept: application/json' \
--data 'grant_type=client_credentials&client_id=himall&client_secret=secret&scope=profile'
返回结果:
{
"access_token": "eyJraWQiOiJkZTYxMjVmNi0wYTQ5LTQwMGYtYWMzMC02M2U2Zm",
"scope": "profile",
"token_type": "Bearer",
"expires_in": 35999
}
用户信息获取:
# 将accessToken替换为上面步骤获取的访问令牌
$ curl --location --request POST 'http://auth.hiauth.cn/userinfo' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer accessToken'
返回结果
{
"sub": "corpadmin",
"empId": 1,
"avatarUrl": "/unpapi/image/2c924149ddfe4bd181959ee9bede10c0.jpeg",
"appId": 91,
"name": "企业管理员",
"phoneNum": "13400000001",
"userId": 11,
"authorities": [],
"cid": 1,
"username": "corpadmin"
}
scop权限:
- 在授权请求中包含所需scope
- 获取的访问令牌将包含授予的scope
- 资源服务器验证请求的scope是否匹配
@PreAuthorize("#oauth2.hasScope('profile')")
@GetMapping("/protected")
public String protectedResource() {
return "Accessed protected resource";
}
如果群二维码失效了,请先添加我的微信,然我我拉你入群。
本项目执行 MIT 协议