tsk-20: Obtain refresh token (#24)

Closes #20

Reviewed-on: phoenix/textsender-auth#24
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-11-21 20:49:38 +00:00
committed by phoenix
parent 0a00282ba7
commit 371dc38958
11 changed files with 640 additions and 0 deletions
+143
View File
@@ -117,6 +117,51 @@ const docTemplate = `{
}
}
},
"/service/login": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Servce login and be given an access token (requires JWT)",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"service users"
],
"summary": "Service login",
"parameters": [
{
"description": "Data to obtain a service token",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/handler.ServiceLoginRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handler.ServiceLoginResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handler.ServiceLoginResponse"
}
}
}
}
},
"/service/register": {
"post": {
"security": [
@@ -167,6 +212,57 @@ const docTemplate = `{
}
}
}
},
"/token/refresh": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Refresh token endpoint (requires JWT)",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"refresh"
],
"summary": "Obtain a refresh token",
"parameters": [
{
"description": "Data to refresh token",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/handler.RefreshRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handler.RefreshResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handler.RefreshResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handler.RefreshResponse"
}
}
}
}
}
},
"definitions": {
@@ -195,6 +291,28 @@ const docTemplate = `{
}
}
},
"handler.RefreshRequest": {
"type": "object",
"properties": {
"access_token": {
"type": "string"
}
}
},
"handler.RefreshResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/token.Login"
}
},
"message": {
"type": "string"
}
}
},
"handler.RegisterResponse": {
"type": "object",
"properties": {
@@ -262,6 +380,31 @@ const docTemplate = `{
}
}
},
"handler.ServiceLoginRequest": {
"type": "object",
"properties": {
"passphrase": {
"type": "string"
},
"username": {
"type": "string"
}
}
},
"handler.ServiceLoginResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/token.Login"
}
},
"message": {
"type": "string"
}
}
},
"token.Login": {
"type": "object",
"properties": {
+143
View File
@@ -111,6 +111,51 @@
}
}
},
"/service/login": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Servce login and be given an access token (requires JWT)",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"service users"
],
"summary": "Service login",
"parameters": [
{
"description": "Data to obtain a service token",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/handler.ServiceLoginRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handler.ServiceLoginResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handler.ServiceLoginResponse"
}
}
}
}
},
"/service/register": {
"post": {
"security": [
@@ -161,6 +206,57 @@
}
}
}
},
"/token/refresh": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Refresh token endpoint (requires JWT)",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"refresh"
],
"summary": "Obtain a refresh token",
"parameters": [
{
"description": "Data to refresh token",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/handler.RefreshRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handler.RefreshResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handler.RefreshResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handler.RefreshResponse"
}
}
}
}
}
},
"definitions": {
@@ -189,6 +285,28 @@
}
}
},
"handler.RefreshRequest": {
"type": "object",
"properties": {
"access_token": {
"type": "string"
}
}
},
"handler.RefreshResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/token.Login"
}
},
"message": {
"type": "string"
}
}
},
"handler.RegisterResponse": {
"type": "object",
"properties": {
@@ -256,6 +374,31 @@
}
}
},
"handler.ServiceLoginRequest": {
"type": "object",
"properties": {
"passphrase": {
"type": "string"
},
"username": {
"type": "string"
}
}
},
"handler.ServiceLoginResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/token.Login"
}
},
"message": {
"type": "string"
}
}
},
"token.Login": {
"type": "object",
"properties": {
+90
View File
@@ -16,6 +16,20 @@ definitions:
message:
type: string
type: object
handler.RefreshRequest:
properties:
access_token:
type: string
type: object
handler.RefreshResponse:
properties:
data:
items:
$ref: '#/definitions/token.Login'
type: array
message:
type: string
type: object
handler.RegisterResponse:
properties:
data:
@@ -59,6 +73,22 @@ definitions:
message:
type: string
type: object
handler.ServiceLoginRequest:
properties:
passphrase:
type: string
username:
type: string
type: object
handler.ServiceLoginResponse:
properties:
data:
items:
$ref: '#/definitions/token.Login'
type: array
message:
type: string
type: object
token.Login:
properties:
access_token:
@@ -150,6 +180,34 @@ paths:
summary: Register user
tags:
- users
/service/login:
post:
consumes:
- application/json
description: Servce login and be given an access token (requires JWT)
parameters:
- description: Data to obtain a service token
in: body
name: request
required: true
schema:
$ref: '#/definitions/handler.ServiceLoginRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/handler.ServiceLoginResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handler.ServiceLoginResponse'
security:
- BearerAuth: []
summary: Service login
tags:
- service users
/service/register:
post:
consumes:
@@ -182,6 +240,38 @@ paths:
summary: Register service user
tags:
- service users
/token/refresh:
post:
consumes:
- application/json
description: Refresh token endpoint (requires JWT)
parameters:
- description: Data to refresh token
in: body
name: request
required: true
schema:
$ref: '#/definitions/handler.RefreshRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/handler.RefreshResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/handler.RefreshResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handler.RefreshResponse'
security:
- BearerAuth: []
summary: Obtain a refresh token
tags:
- refresh
securityDefinitions:
BearerAuth:
description: JWT Bearer Token