# README
App Invite Service
Deployed Solution
The API is deployed at https://pulseid-fur355ca3q-uc.a.run.app
The API documentation is deployed at https://pulseid.web.app
Requirements
Create a service that will facilitate the invite token generation and validation for the Catalyst Experience App.
An invite token is a 6 to 12 digit alphanumeric string that app admins can share with potential customers.
The user workflow is as follow
- The App Admin generates an invitation token using a web app
- The invite token is then used to login into the Catalyst Experience App The outcome of the action above can be either a successful login or the user is asked to retry.
Basic functional requirements
- The APIs should be RESTfull
- The admin endpoints should be authenticated. Propose an easy auth mechanism
- Invite tokens to expire after 7 days
- Invite tokens can be recalled (disabled)
- A public endpoint for validating the invite token
Nice to have functional requirements
- The invite token validation logic needs to be throttled (limit the requests coming from a specific client)
- An admin can get an overview of active and inactive tokens
Basic nonfunctional requirements
- Design and document the APIs that will facilitate the workflow outlined above
- Develop the API in GO
- Use any framework or library that will help you develop the solution faster
- Make sure your code is well-formatted, clean, and follows best practices
- Separate concerns
- Write testable code
- Use in-memory storage for the tokens
Nice to have nonfunctional requirements
- Document the APIs in Swagger or a similar tool
- Write functional code
- Tests, all levels of them
- Use an actual DB (MySQL is preferred)
- Provide deployment instructions
Implementation Server
The app follows the Twelve-Factor-App-Principles
Environment variables
# database configurations
export PULSE_ENV="dev"
export PULSE_DB_USER="root"
export PULSE_DB_PWD=""
export PULSE_DB_NAME="pulse"
export PULSE_DB_PORT="3306"
export PULSE_DB_CLOUD=false
export PULSE_DB_HOST="127.0.0.1"
export PULSE_DB_TIMEZONE="Africa/Nairobi"
export PULSE_DB_INSTANCE_CONNECTION_NAME="theta-outrider-342406:us-central1:wallet"
Authentication
The service uses the basic Authorization scheme.
username: myusername
password: pass@123
Use base64 tool to encode the username and password joined by a colon
# base64 encode the username and password
echo "myusername:pass@123" | base64 -
bWFsdWtpbXV0aHVzaTpwYXNzMTIzCg==
For the endpoints that require authentication, use the generated string. Send the header
Authorization: Basic bWFsdWtpbXV0aHVzaTpwYXNzMTIzCg==
/generate
# Send request
curl -H "Authorization: Basic bWFsdWtpbXV0aHVzaTpwYXNzMTIzCg==" http://localhost:8080/generate
API Documentation
To generate the documentation for the swagger specification
# generate an html documentation of your api
java \
-jar $HOME/programs/swagger-codegen-cli.jar generate \
-i swagger.yml \
-l html2 \
-o docs
Host the documentation
The folder api-docs can be deployed. as a documentation for the API.
In this example I will host the documentation on firebase, follow the documentation at firebase-hosting
# deploy
firebase deploy --only hosting:pulseid
The api documentation is deployed at https://pulseid.web.app