This repository contains the typescript client library for kingdom-auth.
While kingdom-auth is in open preview (pre-release), it is not distributed via npm. For now, install it like this:
npm install https://github.com/5000K/kingdom-auth-typescript.git
yarn add https://github.com/5000K/kingdom-auth-typescript.gitPlease refer to the main repo for info on how to set-up kingdom auth.
import {KingdomAuth} from "kingdom-auth";
async function authExample(){
const client = new KingdomAuth("http://localhost:14414")
const providers = await client.loadProviders();
// authenticate - the provider should probably be selected by your user!
await client.authenticate(providers[0])
// get the token (send this to your services)
const token = await client.getToken();
}The token given out by the client will be short-lived (defaults to 90 seconds). The intended design is to use client.getToken whenever you need a token, the client will make sure that it's always up to date.
The token will be signed with the private key you specified when setting up your kingdom-auth instance. Use the corresponding public key to verify the token within your services (e.g. in an authentication-middleware). It's a JWT as per RFC 7519.