Skip to content

Commit

Permalink
feat(auth): use JWT tokens
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Mishra <[email protected]>
  • Loading branch information
GMishx committed Jan 5, 2024
1 parent c426332 commit dba59dc
Show file tree
Hide file tree
Showing 14 changed files with 389 additions and 106 deletions.
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only

# How long the token can be valid
TOKEN_HOUR_LIFESPAN=24
# Secret key to sign tokens (openssl rand -hex 32)
API_SECRET=some-random-string
91 changes: 75 additions & 16 deletions cmd/laas/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const docTemplate = `{
"get": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Get all audit records from the server",
Expand Down Expand Up @@ -62,7 +62,7 @@ const docTemplate = `{
"get": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Get a specific audit records by ID",
Expand Down Expand Up @@ -112,7 +112,7 @@ const docTemplate = `{
"get": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Get changelogs of an audit record",
Expand Down Expand Up @@ -162,7 +162,7 @@ const docTemplate = `{
"get": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Get a specific changelog of an audit record by its ID",
Expand Down Expand Up @@ -333,7 +333,7 @@ const docTemplate = `{
"post": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Create a new license in the service",
Expand Down Expand Up @@ -428,7 +428,7 @@ const docTemplate = `{
"patch": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Update a license in the service",
Expand Down Expand Up @@ -495,6 +495,46 @@ const docTemplate = `{
}
}
},
"/login": {
"post": {
"description": "Login to get JWT token",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Users"
],
"summary": "Login",
"operationId": "Login",
"parameters": [
{
"description": "Login credentials",
"name": "user",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.UserLogin"
}
}
],
"responses": {
"200": {
"description": "JWT token",
"schema": {
"type": "object",
"properties": {
"token": {
"type": "string"
}
}
}
}
}
}
},
"/obligation_maps/license/{license}": {
"get": {
"description": "Get obligation maps for a given license shortname",
Expand Down Expand Up @@ -577,7 +617,7 @@ const docTemplate = `{
"put": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Replaces the license list of an obligation topic with the given list in the obligation map.",
Expand Down Expand Up @@ -634,7 +674,7 @@ const docTemplate = `{
"patch": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Add or remove licenses from obligation map for a given obligation topic",
Expand Down Expand Up @@ -736,7 +776,7 @@ const docTemplate = `{
"post": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Create an obligation and associate it with licenses",
Expand Down Expand Up @@ -831,7 +871,7 @@ const docTemplate = `{
"delete": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Deactivate an obligation",
Expand Down Expand Up @@ -870,7 +910,7 @@ const docTemplate = `{
"patch": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Update an existing obligation record",
Expand Down Expand Up @@ -982,7 +1022,7 @@ const docTemplate = `{
"get": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Get all service users",
Expand Down Expand Up @@ -1015,7 +1055,7 @@ const docTemplate = `{
"post": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Create a new service user",
Expand Down Expand Up @@ -1067,7 +1107,7 @@ const docTemplate = `{
"get": {
"security": [
{
"BasicAuth": []
"ApiKeyAuth": []
}
],
"description": "Get a single user by ID",
Expand Down Expand Up @@ -1812,6 +1852,22 @@ const docTemplate = `{
}
}
},
"models.UserLogin": {
"type": "object",
"required": [
"password",
"username"
],
"properties": {
"password": {
"type": "string"
},
"username": {
"type": "string",
"example": "fossy"
}
}
},
"models.UserResponse": {
"type": "object",
"properties": {
Expand All @@ -1832,8 +1888,11 @@ const docTemplate = `{
}
},
"securityDefinitions": {
"BasicAuth": {
"type": "basic"
"ApiKeyAuth": {
"description": "Token from /login endpoint",
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}`
Expand Down
Loading

0 comments on commit dba59dc

Please sign in to comment.