Skip to content

A requests library for the Quid json web tokens server

License

Notifications You must be signed in to change notification settings

teal-finance/quidjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QuidJS

pub package

A requests library for the Quid json web tokens server

This library transparently manages the JWT authentication when accessing an API servers: If the API server returns a 401 Unauthorized response when an Access Token is expired, then this QuidJS client library requests a new Access Token from a Quid server using a Refresh Token, and sends again the failed request with the new Access Token.

Add QuidJS as a dependency

yarn add quidjs
# or
npm install quidjs

Usage

import { useQuidRequests } from "quidjs";

const quid = useQuidRequests({
  namespace: "my_namespace",
  quidUri: "https://localhost:8082",   // URL of your Quid server
  serverUri: "https://localhost:8000", // URL of your API backend
  verbose: true,
});

// login the user
await quid.login("user", "pwd");

// use the quid instance to request your API backend
// GET request
const response: Record<string,any> = await quid.get<Record<string,any>>("/api/get");
console.log("Backend GET response:", response)
// POST request
const payload = {"foo": "bar"};
const response2: Record<string,any> = await quid.post<Record<string,any>>("/api/post", payload);
console.log("Backend POST response:", response2)

Examples

Run the tests

Create a test namespace in a Quid instance and create a user. Open tests/src/conf.ts and update the namespace key and credentials. Then run the tests:

yarn test

About

A requests library for the Quid json web tokens server

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •