Git Product home page Git Product logo

okaybackend2fa's Introduction

OkayBackend2FA

This project has a live API demo to check the each feature.

Requirements

Before to start make sure that you already have installed the following tools:

npm
node
curl or postman to test the endpoints

Install dependecies.

To install the dependencies run the following command:

npm install

1. Setup the Okay account

1.1 Create an Account in the Okay Website

To use the Okay API we are required to create an account in the Okay's website.

1.2 Register your server as a Tenant.

Once you are logged in Okay, go to "Tenants" in the top toolbar, then click on "Tenants" from the drop down menu.

1.2.1 What is a Tenant?

In our case, a Tenant is a registry of an endpoint that connects in a secure way to the Okay server in order to link users and manage their Authentication/Authorization procedures.

Each Tenant registry has:

id - This is assigned by Okay 
name - a name to indetify the Tenant
callback URL - An accessible endpoint
status - A Tenant status
trialExpires - The date when your trial expires

Note: the Callback URL is an endpoint where Okay will send POST request to your server and it must be securely accessible.

2. Configuration file.

After installing dependencies is necessary create a configuration file called "config.json" . This file contains information about the Tenant (Including its token/secret). Also the file defines if the server accepts requests over HTTPS (mode: 1 for accepting requests without HTTP and 2 for accepting connections over HTTPS ). Finally the file contains the location of all the "pem" files that we need to accept connections over HTTPS.

{
"tenant":"tenantNumber",
"token":"secret",
"mode":"1",
"keyPem":"cert/key.pem",
"certPem":"cert/cert.pem",
"caPem":"/cert/chain.pem"
}

3. API

In the project we are going to use SQLite to store our data, we will to set up two tables: Users and Sessions. The project has an API to manage each table.

3.1 Users

To get all users visit the following URLs

-- in the live demo
https://hackergt.tech:3000/users/
-- in the localhost
http://localhost:3000/users/
3.1.1 Create Users

To create a new user make the following POST request on Postman or CURL

-- create user in the live demo:
curl -H "Content-Type: application/json" -X POST -d '{"user":{ "name":"jose","email":"[email protected]" }}' https://hackergt.tech:3000/users/create

- create user in localhost
curl -H "Content-Type: application/json" -X POST -d '{"user":{ "name":"jose","email":"[email protected]" }}' http://localhost:3000/users/create
--
3.1.2 Link Users

In order to link a user to Okay we need to request a code generated by the Okay's server, to link a user make the following POST request:

-- link user in the live demo
curl -H "Content-Type: application/json" -X POST -d '{"id":"1"}' https://hackergt.tech:3000/link/

-- link user in the localhost
curl -H "Content-Type: application/json" -X POST -d '{"id":"1"}' http://localhost:3000/link/

3.2 Authenticate/Authorize Sessions

After Linking a user, we can now authenticate that user or authotize the user's action.

3.2.1 Authenticate/Authorize POST request

To make a POST request an Authentication or Authorization we need to run the following:

-- request Authentication/Authorization using the live demo
curl -H "Content-Type: application/json" -X POST -d '{"id":"1"}' https://hackergt.tech:3000/auth/
-- request Authentication/Authorization using the local project
curl -H "Content-Type: application/json" -X POST -d '{"id":"1"}' http://localhost:3000/auth/
3.2.2 Get the completed auth sessions.

We can consider an Auth Session complete when the Okay server sends the success callback to our server endpoint. The current project get track about that sessions. To get the completed sessions we need to go to:

-in the live demo
https://hackergt.tech:3000/auth/completed
-in the localhost we can not get information about the completed sessions.
3.2.3 Get the incomplete auth sessions.

The sessions that for some reason are incomplete can be accessed in the following site:

-in the live demo
https://hackergt.tech:3000/auth/pending

-in the localhost we cannot update the auth session status  because the server can not be reached by the Okay's -server callback.

http://localhost:3000/auth/pending
3.2.4 Getting the Status for a Auth session.

To know the current status of an Auth session in the Okay's server, we must make the following GET request:

-The "170347" identifier is a Auth Session External Id. in the live demo. 
https://hackergt.tech:3000/auth/check/170347

-in the localhost:
http://localhost:3000/auth/check/170347

3.3 Callback Endpoint

In order to receive the Okay's server callbacks we have an Endpoint on:

-In the live demo.
https://hackergt.tech:3000/callback

This endpoint checks the signature of every request from Okay's server using the the shared secret to avoid compromise security.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.