Skip to content

Commit

Permalink
Merge pull request #16 from Nuxify/feature/custom-jwt-authenticator
Browse files Browse the repository at this point in the history
feat: custom jwt authenticator middleware response
  • Loading branch information
kabaluyot authored Oct 31, 2024
2 parents 947b6da + 80bb924 commit fb20c0d
Show file tree
Hide file tree
Showing 14 changed files with 459 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ API_URL_GRPC=http://localhost
API_URL_GRPC_PORT=9090
API_URL_REST=http://localhost
API_URL_REST_PORT=8000
API_VERSION=v1.4.0
API_VERSION=v1.5.0

DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=

JWT_SECRET=

OPENAPI_DOCS_PASSWORD=
225 changes: 217 additions & 8 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,67 @@
}
],
"paths": {
"/record/token/generate": {
"post": {
"tags": ["record"],
"summary": "Generate Token",
"description": "Generates a token",
"responses": {
"201": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/components/schemas/GenerateTokenResponse"
}
}
}
]
}
}
}
},
"4xx": {
"description": "Client side errors",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIErrorResponse"
}
}
}
},
"5xx": {
"description": "Server side errors",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIErrorResponse"
}
}
}
}
}
}
},
"/record": {
"post": {
"tags": ["record"],
"summary": "Create Record",
"description": "Creates a record",
"security": [
{
"bearerAuth": []
}
],
"requestBody": {
"description": "Creates a record request",
"content": {
Expand All @@ -48,14 +104,47 @@
"required": true
},
"responses": {
"2xx": {
"description": "Success"
"201": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/components/schemas/CreateRecordResponse"
}
}
}
]
}
}
}
},
"4xx": {
"description": "Client side errors"
"description": "Client side errors",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIErrorResponse"
}
}
}
},
"5xx": {
"description": "Server side errors"
"description": "Server side errors",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIErrorResponse"
}
}
}
}
}
}
Expand All @@ -65,6 +154,11 @@
"tags": ["record"],
"summary": "Get Record By ID",
"description": "Get record by its id",
"security": [
{
"bearerAuth": []
}
],
"parameters": [
{
"name": "id",
Expand All @@ -77,14 +171,47 @@
}
],
"responses": {
"2xx": {
"description": "Success"
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/APIResponse"
},
{
"type": "object",
"properties": {
"items": {
"$ref": "#/components/schemas/GetRecordResponse"
}
}
}
]
}
}
}
},
"4xx": {
"description": "Client side errors"
"description": "Client side errors",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIErrorResponse"
}
}
}
},
"5xx": {
"description": "Server side errors"
"description": "Server side errors",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/APIErrorResponse"
}
}
}
}
}
}
Expand All @@ -103,6 +230,88 @@
"type": "string"
}
}
},
"APIResponse": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": true
},
"message": {
"type": "string",
"example": "Operation successful"
},
"data": {
"type": "object",
"example": {}
}
}
},
"APIErrorResponse": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": false
},
"message": {
"type": "string",
"example": "Bad Request"
},
"errorCode": {
"type": "string",
"example": "BAD_REQUEST"
},
"data": {
"type": "object",
"example": {}
}
}
},
"CreateRecordResponse": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"data": {
"type": "string"
},
"createdAt": {
"type": "integer"
}
}
},
"GenerateTokenResponse": {
"type": "object",
"properties": {
"accessToken": {
"type": "string"
}
}
},
"GetRecordResponse": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"data": {
"type": "string"
},
"createdAt": {
"type": "integer"
}
}
}
},
"securitySchemes": {
"bearerAuth": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT",
"description": "Session token"
}
}
}
Expand Down
18 changes: 14 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ require (
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/go-chi/chi v1.5.4
github.com/go-chi/cors v1.2.1
github.com/go-chi/jwtauth v1.2.0
github.com/go-playground/validator/v10 v10.16.0
github.com/go-sql-driver/mysql v1.7.0
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/protobuf v1.5.3
github.com/jmoiron/sqlx v1.3.5
github.com/joho/godotenv v1.5.1
github.com/segmentio/ksuid v1.0.4
golang.org/x/crypto v0.7.0
golang.org/x/crypto v0.21.0
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.30.0
)
Expand All @@ -21,10 +23,18 @@ require (
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lestrrat-go/backoff/v2 v2.0.7 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx v1.1.0 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
)
Loading

0 comments on commit fb20c0d

Please sign in to comment.