Tweaking ping titles and body constructs

This commit is contained in:
🐙PiperYxzzy
2022-05-05 23:15:59 +02:00
parent 99402ebdf0
commit 403cc51e12
4 changed files with 310 additions and 219 deletions

View File

@@ -56,8 +56,7 @@ const JwtHeader = "jwt"
// @Description Sign a user up for a new account // @Description Sign a user up for a new account
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param userkey body string true "user email" // @Param signup body signup true "The signup information"
// @Param password body string true "user password"
// @Router /signup [post] // @Router /signup [post]
// @Success 200 // @Success 200
// @Failure 400 "userkey missing, or password missing or not strong enough" // @Failure 400 "userkey missing, or password missing or not strong enough"
@@ -104,9 +103,7 @@ func UserSignup() gin.HandlerFunc {
// @Description Secured login for any user accounts // @Description Secured login for any user accounts
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param userkey body string true "user email" // @Param login body login true "Login information"
// @Param password body string true "user password"
// @Param twofactorcode body string false "the 2fa token for the user, if activated"
// @Router /login [post] // @Router /login [post]
// @Success 200 // @Success 200
// @Failure 401 "not found or credentials invalid" // @Failure 401 "not found or credentials invalid"
@@ -165,6 +162,14 @@ func UserLogin() gin.HandlerFunc {
// Parses a given JWT token and attempts to verify the `sub` in that token IFF // Parses a given JWT token and attempts to verify the `sub` in that token IFF
// the token role == "verify". Verifying an already-verified user returns // the token role == "verify". Verifying an already-verified user returns
// a 200OK{next:"login"} without any action // a 200OK{next:"login"} without any action
// @Summary User verify
// @Description Email verification based on a token sent to a registered email
// @Accept json
// @Produce json
// @Param verify query string true "Verification JWT"
// @Router /verify [post]
// @Success 200
// @Failure 401 "bad token"
func UserVerify() gin.HandlerFunc { func UserVerify() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
verifyJwt, _ := c.GetQuery("verify") verifyJwt, _ := c.GetQuery("verify")
@@ -222,7 +227,7 @@ func UserVerify() gin.HandlerFunc {
// @Description Request a password reset for the provided userkey // @Description Request a password reset for the provided userkey
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param userkey body string true "user email to reset" // @Param userkey body forgotten true "email to reset"
// @Router /forgot [post] // @Router /forgot [post]
// @Success 200 // @Success 200
// @Failure 400 "userkey not provided" // @Failure 400 "userkey not provided"
@@ -251,8 +256,7 @@ func UserForgotPassword() gin.HandlerFunc {
// @Description Use a JWT token to validate and reset a password // @Description Use a JWT token to validate and reset a password
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param token body string true "the token emailed to the user" // @Param reset body reset true "the reset token and the password"
// @Param password body string true "the new password value"
// @Router /reset [post] // @Router /reset [post]
// @Success 200 // @Success 200
// @Failure 400 "token and password not provided" // @Failure 400 "token and password not provided"
@@ -304,13 +308,11 @@ func UserResetForgottenPassword() gin.HandlerFunc {
} }
// Admin login functionality, similar to user login but requires 2FA to be set up. // Admin login functionality, similar to user login but requires 2FA to be set up.
// @Summary User login // @Summary Admin login
// @Description Secured login for any user accounts // @Description Secured login for any user accounts
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param userkey body string true "user email" // @Param login body login true "email, password and 2FA code. 2FA code is required"
// @Param password body string true "user password"
// @Param twofactorcode body string true "the 2fa token"
// @Router /admin [post] // @Router /admin [post]
// @Success 200 // @Success 200
// @Failure 401 "not found or credentials invalid" // @Failure 401 "not found or credentials invalid"
@@ -495,10 +497,10 @@ func StarterAdmin() gin.HandlerFunc {
} }
// Ping functionality // Ping functionality
// @Summary ping example // @Summary Unauthenticated Ping
// @Description unauthenticated ping
// @Product json // @Product json
// @Router /doot [get] // @Router /doot [get]
// @Success 200
func Doot() gin.HandlerFunc { func Doot() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
piCtx, exists := c.Get("principal") piCtx, exists := c.Get("principal")
@@ -512,20 +514,20 @@ func Doot() gin.HandlerFunc {
} }
} }
// @Summary ping example // @Summary User ping
// @Description user ping and login check
// @Product json // @Product json
// @Router /sec/doot [get] // @Router /sec/doot [get]
// @Param jwt header string true "JWT Cookie set by /login" // @Param jwt header string true "JWT Cookie set by /login"
// @Success 200
func UserDoot() gin.HandlerFunc { func UserDoot() gin.HandlerFunc {
return Doot() return Doot()
} }
// @Summary ping example // @Summary Admin ping
// @Description admin ping and login check
// @Product json // @Product json
// @Router /adm/doot [get] // @Router /adm/doot [get]
// @Param jwt header string true "JWT Cookie set by /admin" // @Param jwt header string true "JWT Cookie set by /admin"
// @Success 200
func AdminDoot() gin.HandlerFunc { func AdminDoot() gin.HandlerFunc {
return Doot() return Doot()
} }

View File

@@ -18,8 +18,7 @@ const docTemplate = `{
"paths": { "paths": {
"/adm/doot": { "/adm/doot": {
"get": { "get": {
"description": "admin ping and login check", "summary": "Admin ming",
"summary": "ping example",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
@@ -44,30 +43,12 @@ const docTemplate = `{
"summary": "User login", "summary": "User login",
"parameters": [ "parameters": [
{ {
"description": "user email", "description": "email, password and 2FA code. 2FA code is required",
"name": "userkey", "name": "login",
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/core.login"
}
},
{
"description": "user password",
"name": "password",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "the 2fa token",
"name": "twofactorcode",
"in": "body",
"required": true,
"schema": {
"type": "string"
} }
} }
], ],
@@ -92,8 +73,7 @@ const docTemplate = `{
}, },
"/doot": { "/doot": {
"get": { "get": {
"description": "unauthenticated ping", "summary": "Unauthenticated Ping",
"summary": "ping example",
"responses": {} "responses": {}
} }
}, },
@@ -109,12 +89,12 @@ const docTemplate = `{
"summary": "Forgot password", "summary": "Forgot password",
"parameters": [ "parameters": [
{ {
"description": "user email to reset", "description": "email to reset",
"name": "userkey", "name": "userkey",
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/core.forgotten"
} }
} }
], ],
@@ -140,29 +120,12 @@ const docTemplate = `{
"summary": "User login", "summary": "User login",
"parameters": [ "parameters": [
{ {
"description": "user email", "description": "Login information",
"name": "userkey", "name": "login",
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/core.login"
}
},
{
"description": "user password",
"name": "password",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "the 2fa token for the user, if activated",
"name": "twofactorcode",
"in": "body",
"schema": {
"type": "string"
} }
} }
], ],
@@ -197,21 +160,12 @@ const docTemplate = `{
"summary": "Password reset", "summary": "Password reset",
"parameters": [ "parameters": [
{ {
"description": "the token emailed to the user", "description": "the reset token and the password",
"name": "token", "name": "reset",
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/core.reset"
}
},
{
"description": "the new password value",
"name": "password",
"in": "body",
"required": true,
"schema": {
"type": "string"
} }
} }
], ],
@@ -230,8 +184,7 @@ const docTemplate = `{
}, },
"/sec/doot": { "/sec/doot": {
"get": { "get": {
"description": "user ping and login check", "summary": "User ping",
"summary": "ping example",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
@@ -256,21 +209,12 @@ const docTemplate = `{
"summary": "User signup", "summary": "User signup",
"parameters": [ "parameters": [
{ {
"description": "user email", "description": "The signup information",
"name": "userkey", "name": "signup",
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/core.signup"
}
},
{
"description": "user password",
"name": "password",
"in": "body",
"required": true,
"schema": {
"type": "string"
} }
} }
], ],
@@ -283,6 +227,96 @@ const docTemplate = `{
} }
} }
} }
},
"/verify": {
"post": {
"description": "Email verification based on a token sent to a registered email",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "User verify",
"parameters": [
{
"type": "string",
"description": "Verification JWT",
"name": "verify",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": ""
},
"401": {
"description": "bad token"
}
}
}
}
},
"definitions": {
"core.forgotten": {
"type": "object",
"required": [
"userkey"
],
"properties": {
"userkey": {
"type": "string"
}
}
},
"core.login": {
"type": "object",
"required": [
"password",
"userkey"
],
"properties": {
"password": {
"type": "string"
},
"twofactorcode": {
"type": "string"
},
"userkey": {
"type": "string"
}
}
},
"core.reset": {
"type": "object",
"required": [
"password",
"token"
],
"properties": {
"password": {
"type": "string"
},
"token": {
"type": "string"
}
}
},
"core.signup": {
"type": "object",
"required": [
"password",
"userkey"
],
"properties": {
"password": {
"type": "string"
},
"userkey": {
"type": "string"
}
}
} }
} }
}` }`

View File

@@ -9,8 +9,7 @@
"paths": { "paths": {
"/adm/doot": { "/adm/doot": {
"get": { "get": {
"description": "admin ping and login check", "summary": "Admin ming",
"summary": "ping example",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
@@ -35,30 +34,12 @@
"summary": "User login", "summary": "User login",
"parameters": [ "parameters": [
{ {
"description": "user email", "description": "email, password and 2FA code. 2FA code is required",
"name": "userkey", "name": "login",
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/core.login"
}
},
{
"description": "user password",
"name": "password",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "the 2fa token",
"name": "twofactorcode",
"in": "body",
"required": true,
"schema": {
"type": "string"
} }
} }
], ],
@@ -83,8 +64,7 @@
}, },
"/doot": { "/doot": {
"get": { "get": {
"description": "unauthenticated ping", "summary": "Unauthenticated Ping",
"summary": "ping example",
"responses": {} "responses": {}
} }
}, },
@@ -100,12 +80,12 @@
"summary": "Forgot password", "summary": "Forgot password",
"parameters": [ "parameters": [
{ {
"description": "user email to reset", "description": "email to reset",
"name": "userkey", "name": "userkey",
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/core.forgotten"
} }
} }
], ],
@@ -131,29 +111,12 @@
"summary": "User login", "summary": "User login",
"parameters": [ "parameters": [
{ {
"description": "user email", "description": "Login information",
"name": "userkey", "name": "login",
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/core.login"
}
},
{
"description": "user password",
"name": "password",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "the 2fa token for the user, if activated",
"name": "twofactorcode",
"in": "body",
"schema": {
"type": "string"
} }
} }
], ],
@@ -188,21 +151,12 @@
"summary": "Password reset", "summary": "Password reset",
"parameters": [ "parameters": [
{ {
"description": "the token emailed to the user", "description": "the reset token and the password",
"name": "token", "name": "reset",
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/core.reset"
}
},
{
"description": "the new password value",
"name": "password",
"in": "body",
"required": true,
"schema": {
"type": "string"
} }
} }
], ],
@@ -221,8 +175,7 @@
}, },
"/sec/doot": { "/sec/doot": {
"get": { "get": {
"description": "user ping and login check", "summary": "User ping",
"summary": "ping example",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
@@ -247,21 +200,12 @@
"summary": "User signup", "summary": "User signup",
"parameters": [ "parameters": [
{ {
"description": "user email", "description": "The signup information",
"name": "userkey", "name": "signup",
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/core.signup"
}
},
{
"description": "user password",
"name": "password",
"in": "body",
"required": true,
"schema": {
"type": "string"
} }
} }
], ],
@@ -274,6 +218,96 @@
} }
} }
} }
},
"/verify": {
"post": {
"description": "Email verification based on a token sent to a registered email",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "User verify",
"parameters": [
{
"type": "string",
"description": "Verification JWT",
"name": "verify",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": ""
},
"401": {
"description": "bad token"
}
}
}
}
},
"definitions": {
"core.forgotten": {
"type": "object",
"required": [
"userkey"
],
"properties": {
"userkey": {
"type": "string"
}
}
},
"core.login": {
"type": "object",
"required": [
"password",
"userkey"
],
"properties": {
"password": {
"type": "string"
},
"twofactorcode": {
"type": "string"
},
"userkey": {
"type": "string"
}
}
},
"core.reset": {
"type": "object",
"required": [
"password",
"token"
],
"properties": {
"password": {
"type": "string"
},
"token": {
"type": "string"
}
}
},
"core.signup": {
"type": "object",
"required": [
"password",
"userkey"
],
"properties": {
"password": {
"type": "string"
},
"userkey": {
"type": "string"
}
}
} }
} }
} }

View File

@@ -1,4 +1,44 @@
basePath: /v1 basePath: /v1
definitions:
core.forgotten:
properties:
userkey:
type: string
required:
- userkey
type: object
core.login:
properties:
password:
type: string
twofactorcode:
type: string
userkey:
type: string
required:
- password
- userkey
type: object
core.reset:
properties:
password:
type: string
token:
type: string
required:
- password
- token
type: object
core.signup:
properties:
password:
type: string
userkey:
type: string
required:
- password
- userkey
type: object
info: info:
contact: {} contact: {}
title: Go-Gin Prepack title: Go-Gin Prepack
@@ -6,7 +46,6 @@ info:
paths: paths:
/adm/doot: /adm/doot:
get: get:
description: admin ping and login check
parameters: parameters:
- description: JWT Cookie set by /admin - description: JWT Cookie set by /admin
in: header in: header
@@ -14,31 +53,19 @@ paths:
required: true required: true
type: string type: string
responses: {} responses: {}
summary: ping example summary: Admin ming
/admin: /admin:
post: post:
consumes: consumes:
- application/json - application/json
description: Secured login for any user accounts description: Secured login for any user accounts
parameters: parameters:
- description: user email - description: email, password and 2FA code. 2FA code is required
in: body in: body
name: userkey name: login
required: true required: true
schema: schema:
type: string $ref: '#/definitions/core.login'
- description: user password
in: body
name: password
required: true
schema:
type: string
- description: the 2fa token
in: body
name: twofactorcode
required: true
schema:
type: string
produces: produces:
- application/json - application/json
responses: responses:
@@ -55,21 +82,20 @@ paths:
summary: User login summary: User login
/doot: /doot:
get: get:
description: unauthenticated ping
responses: {} responses: {}
summary: ping example summary: Unauthenticated Ping
/forgot: /forgot:
post: post:
consumes: consumes:
- application/json - application/json
description: Request a password reset for the provided userkey description: Request a password reset for the provided userkey
parameters: parameters:
- description: user email to reset - description: email to reset
in: body in: body
name: userkey name: userkey
required: true required: true
schema: schema:
type: string $ref: '#/definitions/core.forgotten'
produces: produces:
- application/json - application/json
responses: responses:
@@ -84,23 +110,12 @@ paths:
- application/json - application/json
description: Secured login for any user accounts description: Secured login for any user accounts
parameters: parameters:
- description: user email - description: Login information
in: body in: body
name: userkey name: login
required: true required: true
schema: schema:
type: string $ref: '#/definitions/core.login'
- description: user password
in: body
name: password
required: true
schema:
type: string
- description: the 2fa token for the user, if activated
in: body
name: twofactorcode
schema:
type: string
produces: produces:
- application/json - application/json
responses: responses:
@@ -121,18 +136,12 @@ paths:
- application/json - application/json
description: Use a JWT token to validate and reset a password description: Use a JWT token to validate and reset a password
parameters: parameters:
- description: the token emailed to the user - description: the reset token and the password
in: body in: body
name: token name: reset
required: true required: true
schema: schema:
type: string $ref: '#/definitions/core.reset'
- description: the new password value
in: body
name: password
required: true
schema:
type: string
produces: produces:
- application/json - application/json
responses: responses:
@@ -145,7 +154,6 @@ paths:
summary: Password reset summary: Password reset
/sec/doot: /sec/doot:
get: get:
description: user ping and login check
parameters: parameters:
- description: JWT Cookie set by /login - description: JWT Cookie set by /login
in: header in: header
@@ -153,25 +161,19 @@ paths:
required: true required: true
type: string type: string
responses: {} responses: {}
summary: ping example summary: User ping
/signup: /signup:
post: post:
consumes: consumes:
- application/json - application/json
description: Sign a user up for a new account description: Sign a user up for a new account
parameters: parameters:
- description: user email - description: The signup information
in: body in: body
name: userkey name: signup
required: true required: true
schema: schema:
type: string $ref: '#/definitions/core.signup'
- description: user password
in: body
name: password
required: true
schema:
type: string
produces: produces:
- application/json - application/json
responses: responses:
@@ -180,4 +182,23 @@ paths:
"400": "400":
description: userkey missing, or password missing or not strong enough description: userkey missing, or password missing or not strong enough
summary: User signup summary: User signup
/verify:
post:
consumes:
- application/json
description: Email verification based on a token sent to a registered email
parameters:
- description: Verification JWT
in: query
name: verify
required: true
type: string
produces:
- application/json
responses:
"200":
description: ""
"401":
description: bad token
summary: User verify
swagger: "2.0" swagger: "2.0"