Authentication Example in GO

This project showcases how to signup, login and authenticate a user with GO as a backend. The corresponding frontend flutter application can be found here.

Requirements

Ensure you have the following prerequisites installed:

  1. GO
  2. MongoDB

And an account for the following services:

  1. MailJet

Setup

  1. Clone the repository
  2. Create a .env file in the root directory and add the following variables:
JWT_KEY=YourSigningKey
ISS=guardianGate://Random String
AUD=guardianKey://Random String
API_KEY=YourAPIKey
MAIL_JET_API_KEY=YourMailJetAPIKey
MAIL_JET_SECRET_KEY=YourMailJetSecretKey

Note: JWT_Key, ISS, AUD, and API_Key can be any random string. Ensure they match between the Flutter app and the backend.

The MailJet API Key and Secret Key on the other hand can be found in your MailJet account.

  1. Run go run main.go to start the server on port 8081.
  2. You can test the server with Postman or the Flutter App.

Run In Postman

Available Routes

Routes reachable without JWT

  1. /auth/signup - POST - Creates a new user
  2. /auth/signin - POST - Logs in a user and returns a JWT
  3. /auth/sendActivationEmail - POST - Verifies a users email address
  4. /auth/activateAccount - POST - Activates a user's account

Routes reachable with JWT

  1. /exampleRestricted/exampleRestricted - POST - Just a dummy route to test the authentication

License

This project is licensed under the MIT License - see the LICENSE file for details.