Public | Automated Build

Last pushed: 9 months ago
Short Description
its meant for testing authorization
Full Description

Infos

Dependencies :

  • express, to run the server and create the routes
  • aws-sdk, to connect to the DynamoDB user database
  • request, to send request to Google OAuth API
  • dotenv, to import environment variables from .env
  • redis, to connect to the Redis token database
  • bunyan, to handle logging

Don't forget to update your .env file.

Setup

(You need Node.js >=6.2 , NPM and
Redis >=3.2 installed)

  1. Clone the repository and run npm install

  2. Create .env according to the template below.

  3. Run redis-server to start Redis

  4. Run node server.js to start the microservice.
    The server will be running on port 4500.

Setup with docker

(You need Docker and Docker-compose installed)

  1. Clone the repository

  2. Create .env according to the template below.

  3. Run docker-compose up. The server will be
    running on the docker machine on port 4500.

Then, you can run :

  • docker-compose logs to see the logs
  • docker-compose start / docker-compose start / docker-compose restart
  • docker-compose --help to see more available commands

Environment variables

Environment variables are set in the .env file,
at the root of the app's folder.

Here is a template for the .env file :

    NODE_ENV=development
    DEFAULT_PROVIDER=google
    TOKEN_EXPIRATION_TIME=3600
    DEFAULT_REDIRECT_URI=http://localhost:4200/sign
    GOOGLE_CLIENT_ID=
    GOOGLE_CLIENT_SECRET=
    AWS_CLIENT_ID=
    AWS_CLIENT_SECRET=
    AWS_REGION=ap-southeast-1
    REDIS_URL=redis://localhost:6379

API

The format returned by all the endpoint is JSON.

All errors are returned in JSON and contains
one of meaningful error code detailed below. For example :

{ "error": "invalid_provider" }

When there is no data to return, a success is returned
in JSON and contains one of meaningful success code
detailed below. For example :

{ "success": "token_revoked" }

GET /about

Return version and status of the microservice.

GET /auth/sign

Require the code provided by google at the end
of the Google OAuth approval Popup.

Optionnaly require the redirect_uri sent to the Google
OAuth approval Popup. By default, it is set to the
DEFAULT_REDIRECT_URI environment variable.

  1. Check the code on Google OAuth API, get the email
    linked to this code.
  2. Check if the email is in the DynamoDB user database,
    get the user linked to this email.
  3. Generate a token and cache it with the user in
    the Redis database.

Return the generated token, the user and
expires_in (in seconds).

Send errors code_param_not_found, invalid_provider.

GET /auth/inspect

Require a token.

  1. Check the token in the Redis token database, get the
    user linked to this token.
  2. Refresh the expiration time.

Return the user and expires_in (in seconds).

Send error token_param_not_found.

GET /auth/revoke

Require a token.

Delete the token from the Redis token database.

Send success token_revoked.

Send error token_param_not_found.

GET /user/create

Require an existing profile_id, a Gmail email
address and an array of roles (or only one).

Create the User with his profile_id, email and
roles in the DynamoDB database.

Send success user_created.

Send errors profile_id_param_not_found,
email_param_not_found, roles_param_not_found,
roles_param_wrong_format.

Docker Pull Command
Owner
supahands
Source Repository

Comments (0)