1.1.9 • Published 2 years ago

thegana-token v1.1.9

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Description

The main goal of Thegana token decoder is to get the provided JWT token to decode and verify using VC algorithm .

Installation

$ npm i thegana-token-decoder

Usage

import express, { Express, Request, Response } from 'express';
import cors from 'cors';
import axios from 'axios';
import { main } from 'thegana-token-decoder';
import https, { ServerOptions } from 'https';

const app: Express = express();
const port = process.env.PORT || 8000;

const fs = require('fs');
// app.use(cors());

app.use(
  cors({
    origin: '*',
    credentials: true,
    methods: 'POST,OPTIONS',
    allowedHeaders: [
      'Authorization',
      'clientid',
      'x-api-key',
      'Content-Type',
      'x-xsrf-token',
      'x-requested-with',
      'origin',
      'accept',
    ],
  })
);

// AWs key verifier

const verifyKey = (key: string) => {
  const REQ_CLIENT_ID = process.env.CLIENT_ID ?? '95800371-9e56-4f30-823a-cfb8aef3726a';
  const CLIENT_ID = key ? JSON.parse(key) : '';
  if (REQ_CLIENT_ID === CLIENT_ID) {
    return true;
  } else {
    return false;
  }
};

app.use(express.json());

//API

app.post('/api/service/token/checker', async (req: Request, res: Response) => {
  try {
    const hedrId: string = JSON.stringify(req.headers.clientid) ?? '';
    const verifiedHdr: boolean = verifyKey(hedrId);
    if (verifiedHdr) {
      const key: string = req.body.key ?? '';
      if (key) {
        //Package used to decode / verify token

        const vcOutput: any = await main(key);
        // console.log('==vc Output from API==');
        // console.log(vcOutput);
        res.send(vcOutput ?? '');
      } else {
        res.status(499).send('Oh no! No Key Found !!!');
      }
    } else {
      res.status(400).send('Oh no! No header key Found !!!');
    }
  } catch (e) {
    return { message: 'Oh no! ERR-' + e };
  }
});

https
  .createServer(
    {
      key: fs.readFileSync('./cert/server.key'),
      cert: fs.readFileSync('./cert/server.cert'),
    },
    app
  )
  .listen(port, () => {
    console.log(`⚡️[server]: Thegana Server is running at https://localhost:${port}`);
  });

Disclaimer

#WEBSITE DISCLAIMER
    The information provided by Thegana ("we", "us" or "our") on the "site" and our mobile application is for general informational purposes only. All information on the Site and our mobile application is provided in good faith, however we make no representation or warranty of any kind, express or implied, regarding the accuracy, adequacy, validity, reliability, availability or completeness of any information on the Site or our mobile application. UNDER NO CIRCUMSTANCE SHALL WE HAVE ANY LIABILITY TO YOU FOR ANY LOSS OR DAMAGE OF ANY KIND INCURRED AS A RESULT OF THE USE OF THE SITE OR OUR MOBILE APPLICATION OR RELIANCE ON ANY INFORMATION PROVIDED ON THE SITE AND OUR MOBILE APPLICATION. YOUR USE OF THE SITE AND OUR MOBILE APPLICATION AND YOUR RELIANCE ON ANY INFORMATION ON THE SITE AND OUR MOBILE APPLICATION IS SOLELY AT YOUR OWN RISK.

#EXTERNAL LINKS DISCLAIMER
    The Site and our mobile application may contain (or you may be sent through the Site or our mobile application) links to other websites or content belonging to or originating from third parties or links to websites and features in banners or other advertising. Such external links are not investigated, monitored, or checked for accuracy, adequacy, validity, reliability, availability or completeness by us. WE DO NOT WARRANT, ENDORSE, GUARANTEE, OR ASSUME RESPONSIBILITY FOR THE ACCURACY OR RELIABILITY OF ANY INFORMATION OFFERED BY THIRD-PARTY WEBSITES LINKED THROUGH THE SITE OR ANY WEBSITE OR FEATURE LINKED IN ANY BANNER OR OTHER ADVERTISING. WE WILL NOT BE A PARTY TO OR IN ANY WAY BE RESPONSIBLE FOR MONITORING ANY TRANSACTION BETWEEN YOU AND THIRD-PARTY PROVIDERS OF PRODUCTS OR SERVICES.

Stay in touch

License

Thegana is MIT licensed.