Categorygithub.com/cvele/authentication-service
module
0.0.0-20240529095637-9d4032787a4f
Repository: https://github.com/cvele/authentication-service.git
Documentation: pkg.go.dev

# README

Authentication Service

Simple authentication service with support for JWT tokens.

Overview

Auth Service is a Golang application that provides a simple API for user authentication. It uses JWT tokens to authenticate users and protect endpoints.

Table of Contents

Usage

The easiest way to get the service up and running is to use Docker. Run the following command from the root of the project:

docker-compose up

Configuration

The following environment variables can be used to configure the application:

NameDescriptionDefault
DB_HOSTHostname for the database serverlocalhost
DB_PORTPort for the database server26257
DB_NAMEName of the databaseauth
DB_USERUsername for the databaseroot
DB_PASSWORDPassword for the database
DB_SSL_MODESSL mode for the database connectiondisable
JWT_SECRET_KEYSecret key for JWT tokens123
TOKEN_TTLTime to live for JWT tokens30m
PORTPort for the HTTP server8080
MIGRATION_PATHPath to database migrations/app/migrations

Endpoints

MethodPathDescription
POST/registerRegister a new user
POST/loginLogin to the application
POST/refreshRefresh a JWT token
POST/validateValidate a JWT token
POST/change-passwordChange the password for a user

/register - User registration

curl --request POST \
  --url http://localhost:8080/register \
  --header 'Content-Type: application/json' \
  --data '{
	"username": "newuser",
	"password": "newpassword"
}'

/login - User login

Request:

curl --request POST \
  --url http://localhost:8080/login \
  --header 'Content-Type: application/json' \
  --data '{
	"username": "newuser",
	"password": "newpassword"
}'

/refresh - Refresh access token

Request:

curl --request POST \
  --url http://localhost:8080/refresh \
  --header 'Content-Type: application/json' \
  --data '{
	"refresh_token": "<token>"
}'

/validate - Validate JWT

Request:

curl --request POST \
  --url http://localhost:8080/validate \
  --header 'Content-Type: application/json' \
  --data '{
	"token": "<token>"
}'

/change-password - Change password

Request:

curl --request POST \
  --url http://localhost:8080/change-password \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer <token>' \
  --data '{
	"old_password": "newpassword",
	"new_password": "newpassword2"
}'

# Packages

No description provided by the author
Package docs Code generated by swaggo/swag.
No description provided by the author