GitBook: [master] 3 pages modified

This commit is contained in:
Jyotirmoy Bandyopadhayaya 2021-07-17 17:58:02 +00:00 committed by gitbook-bot
parent 31cb87c921
commit d114565313
No known key found for this signature in database
GPG Key ID: 07D2180C7B12D0FF
2 changed files with 91 additions and 0 deletions

View File

@ -1,4 +1,5 @@
# Table of contents
* [About](README.md)
* [Usage](usage.md)

90
usage.md Normal file
View File

@ -0,0 +1,90 @@
---
description: How to use this package ??
---
# Usage
To use this package, you need to integrate it in both ends \(i.e. Frontend and Backend\).
## Frontend
At Frontend, integrate as follows :-
{% tabs %}
{% tab title="Initialization" %}
```javascript
const { Randomizer } = require("encrypted-randomizer");
const privateKey = process.env.YOUR_AUTH_KEY;
// set YOUR_AUTH_KEY as an enviornment variable.
const setEncryption = new Randomizer(privateKey);
```
{% endtab %}
{% tab title="Usage" %}
```javascript
var axios = require('axios');
var qs = require('qs');
var data = qs.stringify({
'date': 'value'
});
var config = {
method: 'get',
url: 'http://your.api.host/endpoint',
headers: {
'Authorization': ...,
'Content-Type': ...,
'TS': setEncryption.getTs(); // Sending Timestamp of Request
'ERHS': await setEncryption.sendHeader(); // Sending the Encrypted Token Headers
},
data : data
};
async axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
```
{% endtab %}
{% endtabs %}
## Backend
At Backend, integrate as follows :-
{% tabs %}
{% tab title="Initialization" %}
```javascript
const { Validator } = require("encrypted-randomizer");
const privateKey = process.env.YOUR_AUTH_KEY;
// set same YOUR_AUTH_KEY as an enviornment variable as used above.
```
{% endtab %}
{% tab title="Usage" %}
```javascript
const express = require('express')
const app = express()
const port = 3000
app.get('/endpoint', (req, res) => {
const decryptChecker = new Validator(privateKey , req.headers.TS);
const verificationState = decryptChecker.verifyState(req.headers.ERHS)
if(verificationState == "true")
res.send("It Works !!!")
else
res.send("Auth Key didn't matched. Request Denied !!!")
})
app.listen(port, () => {
console.log(`Backend Running !!`)
})
```
{% endtab %}
{% endtabs %}