Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Jwt | 6,968 | 6,817 | 535 | a day ago | 51 | August 19, 2022 | 10 | bsd-3-clause | PHP | |
A simple library to work with JSON Web Token and JSON Web Signature | ||||||||||
Pyjwt | 4,593 | 9,443 | 1,606 | 4 days ago | 45 | May 12, 2022 | 19 | mit | Python | |
JSON Web Token implementation in Python | ||||||||||
Jsmn | 3,265 | 22 days ago | 89 | mit | C | |||||
Jsmn is a world fastest JSON parser/tokenizer. This is the official repo replacing the old one at Bitbucket | ||||||||||
Node Jwt Simple | 1,320 | 7,828 | 569 | 2 years ago | 13 | March 30, 2019 | 33 | mit | JavaScript | |
JWT(JSON Web Token) encode and decode module for node.js | ||||||||||
Vault Ui | 1,299 | 5 years ago | 3 | October 04, 2017 | 50 | other | JavaScript | |||
Vault-UI — A beautiful UI to manage your Vault, written in React | ||||||||||
Frangipanni | 1,156 | 5 months ago | 6 | April 10, 2021 | 6 | mit | Go | |||
Program to convert lines of text into a tree structure. | ||||||||||
Token Lists | 1,030 | 51 | 12 days ago | 30 | June 16, 2022 | 133 | mit | TypeScript | ||
📚 The Token Lists specification | ||||||||||
Spring Boot Jwt | 1,022 | a year ago | mit | Java | ||||||
JWT auth service using Spring Boot, Spring Security and MySQL | ||||||||||
Jwt | 844 | 6 years ago | mit | Java | ||||||
webapp用户身份认证方案 JSON WEB TOKEN 实现Deme示例,Java版 | ||||||||||
Jsonwebtoken.swift | 659 | 31 | 4 years ago | 14 | November 06, 2017 | 26 | bsd-2-clause | Swift | ||
Swift implementation of JSON Web Token (JWT). |
除了认证相关功能外,还提供了hiauth-mall、hiauth-mgr-svc项目,供用户参考如何集成。
hiauth-mall
,你可以了解如何在第三方应用中集成hiauth授权服务;hiauth-mgr-svc
项目,你可以快速的启动一个微服务项目的框架搭建,亦可以在这里找到一些技术的最佳实践,为你的项目开发提供参考;SpringSecurity
升级到6.0
版本后,用法有不少改动SpringSecurity5
以后已不再支持Authorization Server
,取而代之的事spring-security-oauth2-authorization-server
项目vue-element-admin
换成了AntDesignPro
如果你觉得此项目有价值,请给我点个star,谢谢!
项目地址:bestaone/HiAuth
├─doc 文档目录,架构设计、数据库设计...
├─cicd 持续集成相关脚本
├─hiauth-parent 统一管理依赖(必选)
├─hiauth-server hiauth认证服务(必选)
├─hiauth-resource hiauth资源管理服务,参考如何集成资源服务(参考)
├─hiauth-himall himall是一个demo,参考此项目了解如何集成hiauth(参考)
├─hiauth-mgr-svc hiauth管理端后台服务,基于SpringBoot(可选)
├─hiauth-mgr-fornt hiauth管理端前端代码,基于AntDesignPro(可选)
Oauth2
协议的统一认证、授权系统;SpringBoot
技术栈的微服务框架搭建;authorization_code
模式,HiAuth支持了用户名密码、手机号短信两种认证方式;React
、AntDesign
技术,参考这个项目,你可以自定义开发管理后端;SpringBoot
项目更容易集成到多个平台(SpringCloud、K8S、Istio);MyBaits-Plus
、分页;
前端从
vue-element-admin
换成了AntDesignPro
截图还没来得及做新的
>git clone https://github.com/bestaone/HiAuth.git
在你的mysql
数据库中创建库hiauth,并执行下面脚本:
> HiAuth\doc\hiauth.sql
# 也可以从JAR自己提取相关表结构
# org.springframework.security.oauth2.server.authorization.client/oauth2-registered-client-schema.sql
# org.springframework.security.oauth2.server.authorization/oauth2-authorization-consent-schema.sql
# org.springframework.security.oauth2.server.authorization/oauth2-authorization-schema.sql
需要调整的配置有数据库、redis,默认会使用native.properties
配置,如果和你的环境不一致。
请修改:
# 需要将如下两个文件中的mysql、redis的配置改成自己的
# HiAuth\hiauth-server\src\main\properties\native.properties
# HiAuth\hiauth-mgr-svc\src\main\properties\native.properties
app.host=http://127.0.0.1:8080
database.url=jdbc:mysql://mysql-server:3306/hiauth3?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
database.username=dev
database.password=123456
redis.host=redis-server
redis.port=6379
redis.database=8
redis.password=
# IP 换成你自己的
127.0.0.1 redis-server
127.0.0.1 mysql-server
# 编译后台,会执行单元测试,需要正确配置数据库和redis
>cd HiAuth
>mvn clean install
# 构建前端并启动
>cd HiAuth\hiauth-mgr-front
>yarn install
>yarn start
# 启动hiauth授权服务端
>cd HiAuth\hiauth-server
>mvn spring-boot:run
# 启动hiauth资源服务端
>cd HiAuth\hiauth-resource
>mvn spring-boot:run
# 启动himall
>cd HiAuth\hiauth-himall
>mvn spring-boot:run
# 启动hiauth管理后端
>cd HiAuth\hiauth-mgr-svc
>mvn spring-boot:run
Swagger
地址:http://127.0.0.1:8080/swagger-ui.html
{
"error": "unauthorized",
"error_description": "Full authentication is required to access this resource"
}
code
码复制出来http://127.0.0.1:8080/oauth2/authorize?client_id=demo-client-id&response_type=code&scope=user_info&redirect_uri=http://www.baidu.com
code
换取accessToken
curl --location --request POST 'http://127.0.0.1:8080/oauth2/token?grant_type=authorization_code&code=code&redirect_uri=http://www.baidu.com' \
--header 'Authorization: Basic ZGVtby1jbGllbnQtaWQ6ZGVtby1jbGllbnQtc2VjcmV0'
{
"access_token": "xxxxxx",
"refresh_token": "yyyyy",
"scope": "user_info",
"token_type": "Bearer",
"expires_in": 7199
}
Authorization = Basic base64.encode(client_id:client_secret)
可以在网上找个在线工具生成,或者直接用postman测试,Authorization
选择Basic Auth
,填入对应值即可
accessToken
,返回401,未授权>curl --location --request POST 'http://127.0.0.1:8082/user/info'
{
"error": "unauthorized",
"error_description": "Full authentication is required to access this resource"
}
accessToken
,返回数据curl --location --request POST 'http://127.0.0.1:8082/user/info' --header 'Authorization: Bearer token'
{
"name":"Resource"
}
curl --location --request POST 'http://127.0.0.1:8080/oauth2/token?grant_type=refresh_token&refresh_token=refresh_token' \
--header 'Authorization: Basic ZGVtby1jbGllbnQtaWQ6ZGVtby1jbGllbnQtc2VjcmV0'
{
"access_token": "xxxxxx",
"refresh_token": "yyyyy",
"scope": "user_info",
"token_type": "Bearer",
"expires_in": 6152
}
access_token
接口,设置grant_type=client_credentials
curl --location --request POST 'http://127.0.0.1:8080/oauth2/token?grant_type=client_credentials&scope=user_info' \
--header 'Authorization: Basic ZGVtby1jbGllbnQtaWQ6ZGVtby1jbGllbnQtc2VjcmV0'
{
"access_token": "xxxxxx",
"scope": "user_info",
"token_type": "Bearer",
"expires_in": 7199
}
access_token
接口,设置grant_type=client_credentials
,scope=message.read
> curl --location --request POST 'http://127.0.0.1:8080/oauth2/token?grant_type=client_credentials&scope=message.read' --header 'Authorization: Basic ZGVtby1jbGllbnQtaWQ6ZGVtby1jbGllbnQtc2VjcmV0'
# 返回的 token 的权限范围是 message.read
{
"access_token": "xxxxxx",
"scope": "message.read",
"token_type": "Bearer",
"expires_in": 7199
}
message.read
权限的toke访问用户接口,被拒绝,提示无权限curl --location --request POST 'http://127.0.0.1:8082/user/info' --header 'Authorization: Bearer token'
{
"error": "insufficient_scope",
"error_description": "Insufficient scope for this resource",
"scope": "user_info"
}
所有的127.0.0.1不能使用localhost代替,因为auth会检查域名的合法性,数据库中登记的是127.0.0.1
这里为了演示如何集成HiAuth、提供了一个Demo项目HiMall
。
HiMall是基于SpringBoot
技术的微服务项目,其集成了HiAuth
的认证、授权。
#编译、构建项目
>cd HiAuth\hiaut-himall
>mvn clean install
>mvn spring-boot:run
authorization_code
模式认证本项目执行 MIT 协议
如果群二维码失效了,请先添加我的微信,然我我拉你入群。