This project has a live API demo to check the each feature.
Before to start make sure that you already have installed the following tools:
npm
node
curl or postman to test the endpoints
To install the dependencies run the following command:
npm install
To use the Okay API we are required to create an account in the Okay's website.
Once you are logged in Okay, go to "Tenants" in the top toolbar, then click on "Tenants" from the drop down menu.
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.
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"
}
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.
To get all users visit the following URLs
-- in the live demo
https://hackergt.tech:3000/users/
-- in the localhost
http://localhost:3000/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
--
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/
After Linking a user, we can now authenticate that user or authotize the user's action.
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/
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.
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
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
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.