JWT proto with login & registration

This commit is contained in:
Mephimeow
2026-06-12 09:12:18 +00:00
committed by zero@thinky
parent ea645860cf
commit 321cba3f9b
14 changed files with 1199 additions and 58 deletions
+222 -5
View File
@@ -14,7 +14,224 @@ const docTemplate = `{
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {},
"paths": {
"/api/auth/login": {
"post": {
"description": "Authenticate user with email and password, returns JWT token",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Epta login",
"parameters": [
{
"description": "Login credentials",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_auth.LoginRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/internal_auth.AuthResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/internal_auth.ErrorResponse"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/internal_auth.ErrorResponse"
}
}
}
}
},
"/api/auth/me": {
"get": {
"security": [
{
"Bearer": []
}
],
"description": "Get authenticated user's profile",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Epta get current user",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/internal_auth.UserResponse"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/internal_auth.ErrorResponse"
}
}
}
}
},
"/api/auth/register": {
"post": {
"description": "Create user account with username, email, password",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Epta registration",
"parameters": [
{
"description": "Registration details",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_auth.RegisterRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/internal_auth.UserResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/internal_auth.ErrorResponse"
}
},
"409": {
"description": "Conflict",
"schema": {
"$ref": "#/definitions/internal_auth.ErrorResponse"
}
}
}
}
}
},
"definitions": {
"internal_auth.AuthResponse": {
"type": "object",
"properties": {
"token": {
"type": "string",
"example": "eyJhbGciOiJIUzI1NiIs..."
},
"user": {
"$ref": "#/definitions/internal_auth.UserPublic"
}
}
},
"internal_auth.ErrorResponse": {
"type": "object",
"properties": {
"error": {
"type": "string",
"example": "invalid email or password"
}
}
},
"internal_auth.LoginRequest": {
"type": "object",
"required": [
"email",
"password"
],
"properties": {
"email": {
"type": "string",
"example": "john@example.com"
},
"password": {
"type": "string",
"example": "secret123"
}
}
},
"internal_auth.RegisterRequest": {
"type": "object",
"required": [
"email",
"password",
"username"
],
"properties": {
"email": {
"type": "string",
"example": "john@example.com"
},
"password": {
"type": "string",
"minLength": 6,
"example": "secret123"
},
"username": {
"type": "string",
"maxLength": 30,
"minLength": 3,
"example": "john"
}
}
},
"internal_auth.UserPublic": {
"type": "object",
"properties": {
"created_at": {
"type": "string"
},
"email": {
"type": "string"
},
"id": {
"type": "string"
},
"username": {
"type": "string"
}
}
},
"internal_auth.UserResponse": {
"type": "object",
"properties": {
"user": {
"$ref": "#/definitions/internal_auth.UserPublic"
}
}
}
},
"securityDefinitions": {
"Bearer": {
"description": "Type \"Bearer\" followed by a space and the JWT token.",
@@ -27,12 +244,12 @@ const docTemplate = `{
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "",
Version: "1.0",
Host: "",
BasePath: "",
Schemes: []string{},
Title: "",
Description: "",
Schemes: []string{"http"},
Title: "AegisGuard API",
Description: "API for AegisGuard control plane",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
+225 -2
View File
@@ -1,9 +1,232 @@
{
"schemes": [
"http"
],
"swagger": "2.0",
"info": {
"contact": {}
"description": "API for AegisGuard control plane",
"title": "AegisGuard API",
"contact": {},
"version": "1.0"
},
"paths": {
"/api/auth/login": {
"post": {
"description": "Authenticate user with email and password, returns JWT token",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Epta login",
"parameters": [
{
"description": "Login credentials",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_auth.LoginRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/internal_auth.AuthResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/internal_auth.ErrorResponse"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/internal_auth.ErrorResponse"
}
}
}
}
},
"/api/auth/me": {
"get": {
"security": [
{
"Bearer": []
}
],
"description": "Get authenticated user's profile",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Epta get current user",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/internal_auth.UserResponse"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/internal_auth.ErrorResponse"
}
}
}
}
},
"/api/auth/register": {
"post": {
"description": "Create user account with username, email, password",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Epta registration",
"parameters": [
{
"description": "Registration details",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_auth.RegisterRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/internal_auth.UserResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/internal_auth.ErrorResponse"
}
},
"409": {
"description": "Conflict",
"schema": {
"$ref": "#/definitions/internal_auth.ErrorResponse"
}
}
}
}
}
},
"definitions": {
"internal_auth.AuthResponse": {
"type": "object",
"properties": {
"token": {
"type": "string",
"example": "eyJhbGciOiJIUzI1NiIs..."
},
"user": {
"$ref": "#/definitions/internal_auth.UserPublic"
}
}
},
"internal_auth.ErrorResponse": {
"type": "object",
"properties": {
"error": {
"type": "string",
"example": "invalid email or password"
}
}
},
"internal_auth.LoginRequest": {
"type": "object",
"required": [
"email",
"password"
],
"properties": {
"email": {
"type": "string",
"example": "john@example.com"
},
"password": {
"type": "string",
"example": "secret123"
}
}
},
"internal_auth.RegisterRequest": {
"type": "object",
"required": [
"email",
"password",
"username"
],
"properties": {
"email": {
"type": "string",
"example": "john@example.com"
},
"password": {
"type": "string",
"minLength": 6,
"example": "secret123"
},
"username": {
"type": "string",
"maxLength": 30,
"minLength": 3,
"example": "john"
}
}
},
"internal_auth.UserPublic": {
"type": "object",
"properties": {
"created_at": {
"type": "string"
},
"email": {
"type": "string"
},
"id": {
"type": "string"
},
"username": {
"type": "string"
}
}
},
"internal_auth.UserResponse": {
"type": "object",
"properties": {
"user": {
"$ref": "#/definitions/internal_auth.UserPublic"
}
}
}
},
"paths": {},
"securityDefinitions": {
"Bearer": {
"description": "Type \"Bearer\" followed by a space and the JWT token.",
+149 -1
View File
@@ -1,6 +1,154 @@
definitions:
internal_auth.AuthResponse:
properties:
token:
example: eyJhbGciOiJIUzI1NiIs...
type: string
user:
$ref: '#/definitions/internal_auth.UserPublic'
type: object
internal_auth.ErrorResponse:
properties:
error:
example: invalid email or password
type: string
type: object
internal_auth.LoginRequest:
properties:
email:
example: john@example.com
type: string
password:
example: secret123
type: string
required:
- email
- password
type: object
internal_auth.RegisterRequest:
properties:
email:
example: john@example.com
type: string
password:
example: secret123
minLength: 6
type: string
username:
example: john
maxLength: 30
minLength: 3
type: string
required:
- email
- password
- username
type: object
internal_auth.UserPublic:
properties:
created_at:
type: string
email:
type: string
id:
type: string
username:
type: string
type: object
internal_auth.UserResponse:
properties:
user:
$ref: '#/definitions/internal_auth.UserPublic'
type: object
info:
contact: {}
paths: {}
description: API for AegisGuard control plane
title: AegisGuard API
version: "1.0"
paths:
/api/auth/login:
post:
consumes:
- application/json
description: Authenticate user with email and password, returns JWT token
parameters:
- description: Login credentials
in: body
name: request
required: true
schema:
$ref: '#/definitions/internal_auth.LoginRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/internal_auth.AuthResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/internal_auth.ErrorResponse'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/internal_auth.ErrorResponse'
summary: Epta login
tags:
- auth
/api/auth/me:
get:
consumes:
- application/json
description: Get authenticated user's profile
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/internal_auth.UserResponse'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/internal_auth.ErrorResponse'
security:
- Bearer: []
summary: Epta get current user
tags:
- auth
/api/auth/register:
post:
consumes:
- application/json
description: Create user account with username, email, password
parameters:
- description: Registration details
in: body
name: request
required: true
schema:
$ref: '#/definitions/internal_auth.RegisterRequest'
produces:
- application/json
responses:
"201":
description: Created
schema:
$ref: '#/definitions/internal_auth.UserResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/internal_auth.ErrorResponse'
"409":
description: Conflict
schema:
$ref: '#/definitions/internal_auth.ErrorResponse'
summary: Epta registration
tags:
- auth
schemes:
- http
securityDefinitions:
Bearer:
description: Type "Bearer" followed by a space and the JWT token.