Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]jwt design #85

Closed
wants to merge 1 commit into from
Closed

Conversation

SmilingSea
Copy link

目前是使用的hertz提供的jwt实现github.com/hertz-contrib/jwt以及Golang提供的限流器golang.org/x/time/rate进行接口防刷实现,目前参数都还是写死的,还没有写到接口里面去,等我本地测测再pull request

@ozline
Copy link
Member

ozline commented Nov 8, 2024

同步一下最新的go.mod,学一下基本git用法

limiter, exists := limiterMap[clientIP]
if !exists {
// 创建一个新的速率限制器,限制每秒rps次请求,允许burst次突发请求
limiter = rate.NewLimiter(rate.Limit(rps), burst)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个和现在的Sentinel有什么区别?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实是这样,我貌似把issue里的需求理解错了,是为了防止第三方恶意盗用接口,防刷的话sentinal确实已经解决了,这个中间件就不需要了。

}
username := loginStruct.Username
password := loginStruct.Password
if !(username == "admin" && password == "admin") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么这边要明文绑定?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我马上改

TokenHeadName: "Bearer",
// 登录成功后的响应
LoginResponse: func(ctx context.Context, c *app.RequestContext, code int, token string, expire time.Time) {
c.JSON(http.StatusOK, utils.H{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个格式符合现在apifox上的response吗?

func InitJwt() {
var err error
JwtMiddleware, err = jwt.New(&jwt.HertzJWTMiddleware{
Realm: "test zone",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test zone?

Copy link

codecov bot commented Nov 8, 2024

Codecov Report

Attention: Patch coverage is 0% with 69 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
api/middleware/jwt.go 0.00% 44 Missing ⚠️
api/middleware/rate_limit.go 0.00% 22 Missing ⚠️
api/router/api/middleware.go 0.00% 3 Missing ⚠️
Flag Coverage Δ
unittest 0.91% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
api/router/api/middleware.go 0.00% <0.00%> (ø)
api/middleware/rate_limit.go 0.00% <0.00%> (ø)
api/middleware/jwt.go 0.00% <0.00%> (ø)

@SmilingSea
Copy link
Author

有一个疑问就是 我在签发token的时候 得到传入的参数之后(id password这些)要去哪里验证

@ozline
Copy link
Member

ozline commented Nov 13, 2024

GitHub 账户学一下 GPG commit verification,把前面的 git 记录删掉,现在 merge 必须要求满 verification

ref:https://docs.github.com/zh/authentication/managing-commit-signature-verification/about-commit-signature-verification

@SmilingSea
Copy link
Author

改了一下pr 到 #99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants