From c0fb43df7d6c30007158c3ff301f47805c466248 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Tue, 7 May 2024 22:10:17 -0700 Subject: [PATCH] More testing done around jwt and things are looking ok. Should be able to work on the portal now some. --- .vscode/launch.json | 15 --------- docs/docs.go | 63 +++++++++++++++++++++++++++++++++++-- docs/swagger.json | 63 +++++++++++++++++++++++++++++++++++-- docs/swagger.yaml | 32 +++++++++++++++++-- internal/handler/v1/auth.go | 38 +++++++++++----------- 5 files changed, 172 insertions(+), 39 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index f944eb2..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Launch Package", - "type": "go", - "request": "launch", - "mode": "auto", - "program": "." - } - ] -} \ No newline at end of file diff --git a/docs/docs.go b/docs/docs.go index 58e97ea..f7ce7b5 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -203,6 +203,11 @@ const docTemplate = `{ }, "/v1/discord/webhooks": { "get": { + "security": [ + { + "Bearer": [] + } + ], "produces": [ "application/json" ], @@ -234,6 +239,11 @@ const docTemplate = `{ }, "/v1/discord/webhooks/by/serverAndChannel": { "get": { + "security": [ + { + "Bearer": [] + } + ], "produces": [ "application/json" ], @@ -281,6 +291,11 @@ const docTemplate = `{ }, "/v1/discord/webhooks/new": { "post": { + "security": [ + { + "Bearer": [] + } + ], "tags": [ "DiscordWebhook" ], @@ -369,6 +384,11 @@ const docTemplate = `{ }, "/v1/discord/webhooks/{ID}/disable": { "post": { + "security": [ + { + "Bearer": [] + } + ], "tags": [ "DiscordWebhook" ], @@ -406,6 +426,11 @@ const docTemplate = `{ }, "/v1/discord/webhooks/{ID}/enable": { "post": { + "security": [ + { + "Bearer": [] + } + ], "tags": [ "DiscordWebhook" ], @@ -424,6 +449,11 @@ const docTemplate = `{ }, "/v1/discord/webhooks/{id}": { "get": { + "security": [ + { + "Bearer": [] + } + ], "produces": [ "application/json" ], @@ -810,14 +840,33 @@ const docTemplate = `{ "summary": "Marks a source as deleted based on its ID value.", "parameters": [ { - "type": "string", + "type": "integer", "description": "id", "name": "id", "in": "path", "required": true } ], - "responses": {} + "responses": { + "200": { + "description": "ok", + "schema": { + "$ref": "#/definitions/domain.SourcesResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/domain.BaseResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/domain.BaseResponse" + } + } + } } }, "/v1/sources/{id}/disable": { @@ -1036,6 +1085,11 @@ const docTemplate = `{ }, "/v1/users/scopes/add": { "post": { + "security": [ + { + "Bearer": [] + } + ], "consumes": [ "application/json" ], @@ -1081,6 +1135,11 @@ const docTemplate = `{ }, "/v1/users/scopes/remove": { "post": { + "security": [ + { + "Bearer": [] + } + ], "consumes": [ "application/json" ], diff --git a/docs/swagger.json b/docs/swagger.json index 2e61798..89172d1 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -194,6 +194,11 @@ }, "/v1/discord/webhooks": { "get": { + "security": [ + { + "Bearer": [] + } + ], "produces": [ "application/json" ], @@ -225,6 +230,11 @@ }, "/v1/discord/webhooks/by/serverAndChannel": { "get": { + "security": [ + { + "Bearer": [] + } + ], "produces": [ "application/json" ], @@ -272,6 +282,11 @@ }, "/v1/discord/webhooks/new": { "post": { + "security": [ + { + "Bearer": [] + } + ], "tags": [ "DiscordWebhook" ], @@ -360,6 +375,11 @@ }, "/v1/discord/webhooks/{ID}/disable": { "post": { + "security": [ + { + "Bearer": [] + } + ], "tags": [ "DiscordWebhook" ], @@ -397,6 +417,11 @@ }, "/v1/discord/webhooks/{ID}/enable": { "post": { + "security": [ + { + "Bearer": [] + } + ], "tags": [ "DiscordWebhook" ], @@ -415,6 +440,11 @@ }, "/v1/discord/webhooks/{id}": { "get": { + "security": [ + { + "Bearer": [] + } + ], "produces": [ "application/json" ], @@ -801,14 +831,33 @@ "summary": "Marks a source as deleted based on its ID value.", "parameters": [ { - "type": "string", + "type": "integer", "description": "id", "name": "id", "in": "path", "required": true } ], - "responses": {} + "responses": { + "200": { + "description": "ok", + "schema": { + "$ref": "#/definitions/domain.SourcesResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/domain.BaseResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/domain.BaseResponse" + } + } + } } }, "/v1/sources/{id}/disable": { @@ -1027,6 +1076,11 @@ }, "/v1/users/scopes/add": { "post": { + "security": [ + { + "Bearer": [] + } + ], "consumes": [ "application/json" ], @@ -1072,6 +1126,11 @@ }, "/v1/users/scopes/remove": { "post": { + "security": [ + { + "Bearer": [] + } + ], "consumes": [ "application/json" ], diff --git a/docs/swagger.yaml b/docs/swagger.yaml index a60e835..9eddc06 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -269,6 +269,8 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/domain.BaseResponse' + security: + - Bearer: [] summary: Returns the top 100 tags: - DiscordWebhook @@ -317,6 +319,8 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/domain.BaseResponse' + security: + - Bearer: [] summary: Disables a Webhook from being used. tags: - DiscordWebhook @@ -329,6 +333,8 @@ paths: required: true type: integer responses: {} + security: + - Bearer: [] summary: Enables a source to continue processing. tags: - DiscordWebhook @@ -355,6 +361,8 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/domain.BaseResponse' + security: + - Bearer: [] summary: Returns the top 100 entries from the queue to be processed. tags: - DiscordWebhook @@ -386,6 +394,8 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/domain.BaseResponse' + security: + - Bearer: [] summary: Returns all the known web hooks based on the Server and Channel given. tags: - DiscordWebhook @@ -420,6 +430,8 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/domain.BaseResponse' + security: + - Bearer: [] summary: Creates a new record for a discord web hook to post data to. tags: - DiscordWebhook @@ -480,8 +492,20 @@ paths: in: path name: id required: true - type: string - responses: {} + type: integer + responses: + "200": + description: ok + schema: + $ref: '#/definitions/domain.SourcesResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/domain.BaseResponse' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/domain.BaseResponse' security: - Bearer: [] summary: Marks a source as deleted based on its ID value. @@ -806,6 +830,8 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/domain.BaseResponse' + security: + - Bearer: [] summary: Adds a new scope to a user account tags: - Users @@ -835,6 +861,8 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/domain.BaseResponse' + security: + - Bearer: [] summary: Adds a new scope to a user account tags: - Users diff --git a/internal/handler/v1/auth.go b/internal/handler/v1/auth.go index 9320cb6..f73f57e 100644 --- a/internal/handler/v1/auth.go +++ b/internal/handler/v1/auth.go @@ -20,9 +20,9 @@ const ( // @Router /v1/users/register [post] // @Param request formData domain.LoginFormRequest true "form" // @Accepts x-www-form-urlencoded -// @Produce json +// @Produce json // @Tags Users -// @Success 200 {object} domain.BaseResponse +// @Success 200 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse func (h *Handler) AuthRegister(c echo.Context) error { @@ -62,11 +62,11 @@ func (h *Handler) AuthRegister(c echo.Context) error { // @Router /v1/users/login [post] // @Param request formData domain.LoginFormRequest true "form" // @Accepts x-www-form-urlencoded -// @Produce json -// @Tags Users +// @Produce json +// @Tags Users // @Success 200 {object} domain.LoginResponse -// @Failure 400 {object} domain.BaseResponse -// @Failure 500 {object} domain.BaseResponse +// @Failure 400 {object} domain.BaseResponse +// @Failure 500 {object} domain.BaseResponse func (h *Handler) AuthLogin(c echo.Context) error { username := c.FormValue("username") password := c.FormValue("password") @@ -144,10 +144,10 @@ func (h *Handler) createAdminToken(c echo.Context, password string) error { // @Summary Generates a new token // @Router /v1/users/refreshToken [post] // @Param request body domain.RefreshTokenRequest true "body" -// @Tags Users +// @Tags Users // @Success 200 {object} domain.LoginResponse -// @Failure 400 {object} domain.BaseResponse -// @Failure 500 {object} domain.BaseResponse +// @Failure 400 {object} domain.BaseResponse +// @Failure 500 {object} domain.BaseResponse // @Security Bearer func (h *Handler) RefreshJwtToken(c echo.Context) error { _, err := h.ValidateJwtToken(c, domain.ScopeDiscordWebHookCreate) @@ -193,15 +193,16 @@ func (h *Handler) RefreshJwtToken(c echo.Context) error { }) } -// @Summary Adds a new scope to a user account -// @Router /v1/users/scopes/add [post] -// @Param request body domain.UpdateScopesRequest true "body" +// @Summary Adds a new scope to a user account +// @Router /v1/users/scopes/add [post] +// @Param request body domain.UpdateScopesRequest true "body" // @Tags Users -// @Accept json +// @Accept json // @Produce json -// @Success 200 {object} domain.BaseResponse +// @Success 200 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse +// @Security Bearer func (h *Handler) AddScopes(c echo.Context) error { _, err := h.ValidateJwtToken(c, domain.ScopeAll) if err != nil { @@ -224,15 +225,16 @@ func (h *Handler) AddScopes(c echo.Context) error { }) } -// @Summary Adds a new scope to a user account -// @Router /v1/users/scopes/remove [post] -// @Param request body domain.UpdateScopesRequest true "body" +// @Summary Adds a new scope to a user account +// @Router /v1/users/scopes/remove [post] +// @Param request body domain.UpdateScopesRequest true "body" // @Tags Users -// @Accept json +// @Accept json // @Produce json // @Success 200 {object} domain.BaseResponse // @Failure 400 {object} domain.BaseResponse // @Failure 500 {object} domain.BaseResponse +// @Security Bearer func (h *Handler) RemoveScopes(c echo.Context) error { token, err := h.getJwtTokenFromContext(c) if err != nil {