Key Features • How To Use • Download • Credits • Related • License
- User registration.
- Register a user with firstname, lastname, email, username and password.
- Account activation
- After reistration, activation link sent to email with activation tiken appended to it.
- Token authentication
- Sending a post request with correct email address and password return a token.
- Retrive user and all users
- Protected endpoint that retrieves all users and a specifc user provded with a token.
- Email notification
- Email notifcation sent after registrtion.
To clone and run this application, you'll need Go , Postgres database, make and docker installed on your computer. From your command line:
# Clone this repository
$ git clone [email protected]:rabin-nyaundi/auth-service.git
# Go into the repository
$ cd auth-service
# Create .envrc file
$ touch .envrc
Add the following to `.envrc` file
export DATABASE_DSN=postgresql://<database_user>:<password>@localhost/<database_name>?sslmode=disable
# Create .env file
$ touch .env
Add the following to `.env` file
SMTP_HOST=your_smtp_host
SMTP_PORT=syour_mtp_port
SMTP_USERNAME=your_smtp_username
SMTP_PASSWORD=your_smtp_password
SMTP_SENDER=Task<[email protected]>
# Apply database migrations
$ make db/migrations/new
# Run the app
$ make run/api
# Visit the application url
Visit localhost:4002
# Clone this repository
$ git clone [email protected]:rabin-nyaundi/auth-service.git
# Go into the repository
$ cd auth-service
# Create .env file
$ touch .env
Add the following to `.env` file
DATABASE_DSN=postgresql://<database_user>:<password>@localhost/<database_name>?sslmode=disable
SMTP_HOST=smtp_host
SMTP_PORT=smtp_port
SMTP_USERNAME=smtp_username
SMTP_PASSWORD=smtp_password
SMTP_SENDER=Task<[email protected]>
# Run docker compose up
$ docker-compose up
# Visit the application url
Visit localhost:4002
The REST API to the example app is described below.
POST /v1/users/
BODY='{"firstname":"test", "lastname":"user", "username":"testuser", "email":"[email protected]", "password": "pass@55word" }'
curl -X POST -d "$BODY" http://localhost:4002/v1/users/
{
"user": "user created successfuly"
}
POST /v1/users/activated/
BODY='{"token": "HSKBAPCPVB5I7P627SOH2OKOPA"}',
curl -X POST -d "$BODY" http://localhost:4002/v1/users/activated
{
"data": {
"id": 2,
"firstname": "test",
"lastname": "user",
"username": "testuser",
"email": "[email protected]",
"active": true,
"role": 1,
"CreatedAt": "2022-09-12T20:43:57Z",
"UpdatedAt": "2022-09-12T20:44:21.050272223Z"
}
}
POST /v1/token/authenticate
BODY='{ "email":"[email protected]", "password": "pass@55word"}'
curl -X POST -d "$BODY" http://localhost:4002/v1/token/authenticate
{
"authentication_token": {
"token": "FCK7CD6KHJCV2UDPONJVAXFWGQ",
"expiry": "2022-09-13T20:52:39.605213672Z"
}
}
This software uses the following open source packages: