yanmoai6666-star/go-simple-api

添加用户认证功能(JWT 或 Basic Auth)

Open

#4 opened on Dec 5, 2025

 (0 comments) (0 reactions) (0 assignees)Go (0 forks)auto 404
enhancementhelp wanted

Repository metrics

Stars
 (0 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

当前 API 接口未做权限控制,任何客户端均可直接调用创建/修改接口,存在安全风险。例如:

  • 恶意用户可能创建大量无效用户或产品
  • 无法验证操作发起者的身份,难以追踪责任

建议实现基于 JWT 的认证机制:

  1. 添加 POST /api/v1/auth/login 接口,用户登录后返回令牌
  2. 在需要权限的接口(如创建产品、修改用户)添加中间件验证令牌
  3. 为用户模型添加 Password 字段(需加密存储,如使用 bcrypt)

Contributor guide