OAuth认证平台

一个全栈Web应用程序,提供用户认证功能并作为OAuth 2.0提供商,允许第三方应用程序安全访问用户数据。

  • by gaspiman
  • Go
  • 本地部署
  • 更新于
在 GitHub 查看 gaspiman/ebay-mcp

使用说明

OAuth提供者平台

一个提供用户身份验证并充当OAuth 2.0提供者的全栈web应用程序,允许第三方应用程序安全地访问用户数据。

特性

用户管理

  • 用户注册 -使用电子邮件和密码创建新帐户
  • 用户登录 -使用JWT令牌进行安全身份验证
  • 用户黑板 -查看个人资料信息并管理已连接的应用程序

OAuth 2.0提供程序

  • 授权码流 -完整的OAuth 2.0实现
  • 同意屏幕 -用户可以批准/拒绝第三方应用程序访问
  • 许可证管理 -访问令牌和刷新令牌
  • 用户信息端点 -标准OAuth用户信息端点
  • 基于范围的权限 -精细的访问控制

安全

  • 密码散列 -用盐加密
  • JWT身份验证 -安全会话管理
  • CORS保护 -可配置的跨源策略
  • SQL注入保护 -带有参数化查询的GORM ORM
  • 令牌到期 -自动令牌失效

建筑

┌─────────────┐         ┌─────────────┐         ┌──────────────┐
│             │         │             │         │              │
│   Frontend  │◄───────►│   Backend   │◄───────►│  PostgreSQL  │
│   (React)   │  REST   │    (Go)     │  GORM   │   Database   │
│             │  API    │             │         │              │
└─────────────┘         └─────────────┘         └──────────────┘

技术栈

后端

  • 语言:转到1.21+
  • 框架:杜松子酒
  • 数据库:PostgreSQL与GORM
  • 认证:JWT(高朗JWT/JWT)
  • 密码散列:bcrypt

前端

  • 框架:React 18与TypeScript
  • 路由:React路由器v6
  • 样式:顺风CSS
  • HTTP客户端:Axios
  • 生成工具:创建React应用程序

快速开始

看 设置.md 了解详细的安装说明。

先决条件

  • 转到1.21+
  • Node.js 16+
  • PostgreSQL 12+

安装

  1. 克隆存储库
git clone <repository-url>
cd ebay-mcp
  1. 设置数据库
createdb ebay_mcp_db
  1. 启动后端
cd backend
cp .env.example .env
# Edit .env with your database credentials
go mod download
go run main.go
  1. 启动前端
cd frontend
npm install
npm start
  1. 访问应用程序
  • 前端:http://localhost:3000
  • 后端API:http://localhost:8080

项目结构

ebay-mcp/
├── backend/                    # Go backend server
│   ├── config/                # Configuration management
│   ├── controllers/           # Request handlers
│   ├── database/              # Database setup
│   ├── middleware/            # Middleware functions
│   ├── models/                # Data models
│   ├── routes/                # Route definitions
│   ├── utils/                 # Utility functions
│   ├── main.go               # Entry point
│   ├── go.mod                # Go dependencies
│   └── .env.example          # Environment template
│
├── frontend/                  # React frontend
│   ├── src/
│   │   ├── api/              # API client
│   │   ├── context/          # React Context
│   │   ├── pages/            # Page components
│   │   ├── App.tsx           # Main component
│   │   └── index.tsx         # Entry point
│   ├── public/               # Static files
│   └── package.json          # npm dependencies
│
├── main.go                   # Legacy eBay proxy (separate)
├── SETUP.md                  # Setup instructions
└── README.md                 # This file

API文档

身份验证端点

注册

POST /api/auth/register
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "password123",
  "name": "John Doe"
}

登录

POST /api/auth/login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "password123"
}

OAuth端点

授权

GET /oauth/authorize?client_id={id}&redirect_uri={uri}&response_type=code&scope={scope}&state={state}
Authorization: Bearer {jwt_token}

代币交换

POST /oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code={code}&redirect_uri={uri}&client_id={id}&client_secret={secret}

用户信息

GET /oauth/userinfo
Authorization: Bearer {access_token}

有关API的完整文档,请参阅 后端/README.md.

OAuth流程示例

  1. 第三方应用启动OAuth
https://yourapp.com/oauth/consent?
  client_id=app123&
  redirect_uri=https://thirdparty.com/callback&
  response_type=code&
  scope=read&
  state=random123
  1. 用户登录 (如果尚未认证)

  2. 用户看到同意屏幕 包含应用程序详细信息和权限

  3. 用户批准 → 重定向到…… https://thirdparty.com/callback?code=ABC123&state=random123

  4. 第三方代币交换代码

curl -X POST http://localhost:8080/oauth/token \
  -d "grant_type=authorization_code" \
  -d "code=ABC123" \
  -d "redirect_uri=https://thirdparty.com/callback" \
  -d "client_id=app123" \
  -d "client_secret=secret456"
  1. 响应包含访问令牌
{
  "access_token": "token123",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "refresh456",
  "scope": "read"
}

发展

运行测试

# Backend
cd backend
go test ./...

# Frontend
cd frontend
npm test

生产大楼

# Backend
cd backend
go build -o backend-server main.go

# Frontend
cd frontend
npm run build

安全考虑

  • 在生产环境中始终使用HTTPS
  • 改变 JWT_SECRET 变为强随机值
  • 使用环境变量作为机密
  • 启用数据库SSL连接
  • 实施速率限制
  • 添加日志记录和监控
  • 定期安全更新

贡献

  1. 分叉存储库
  2. 创建要素分支
  3. 进行更改
  4. 提交拉取请求

许可证

麻省理工学院

支持

对于问题和疑问:

  • 检查 设置.md 获取安装帮助
  • 查看中的组件自述文件 后端/ 和 前端/
  • 检查服务器日志是否有错误
  • 确保安装了所有必备组件