kreds

Kreds authentication/API library for node.js

Usage no npm install needed!

<script type="module">
  import kreds from 'https://cdn.skypack.dev/kreds';
</script>

README

Kreds

node.js library for the Kreds API. Built with TypeScript.

Installation

The library is available on npm, you can install it with either npm or yarn:

npm install kreds
# or:
yarn install kreds

Example usage

import Kreds from 'kreds';

const kreds = new Kreds({
    instanceUrl: 'https://auth.example.com',
    clientId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    clientSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    redirectUri: 'https://app.example.com/auth/callback',
});

const authorizeUrl = kreds.authorizeUrl('state');

// Then, after redirection
// Check if 'state' from query parameters is equal to the state provided to the authorizeUrl call.
// Check if 'error' is empty, and then call getToken with the code if everything is fine.

try {
    const { accessToken, refreshToken } = await kreds.authorizationCodeGrant('code');
} catch (e) {
    // Make sure to handle the exception.
}