npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@targetprocess/tokiny

v3.8.0

Published

Client for easy retrieving access_tokens from Targetprocess Auth service.

Downloads

2,395

Readme

Node.js compatibility

Node.js 12 or higher is required. For older Node.js versions use tokiny@^2.0.0.

Targetprocess Tokiny

JavaScript client for retrieving auth access_tokens by OAuth client credentials flow.

Features

  • Allow easily retrieve access_token from Targetprocess Auth service
  • Cache token if specified
  • Does not send multiple requests to auth in case of multiple token retrieve attempts occurred in one time. For token requests with same access parameters only on request will be actually made to auth.

Quick start

To install tokiny use:

npm install  @targetprocess/tokiny

To get new access token from Targetprocess auth:

import {createTokenFactory} from "@targetprocess/tokiny";

const tokenFactory = createTokenFactory({
  authUrl: env.AUTH_SERVICE_URI,
  clientId: env.CLIENT_ID,
  clientSecret: env.CLIENT_SECRET
});

const token = await tokenFactory.getToken("scope1 scope2");

createTokenFsactory as a parameter expects object of type IAuthOptions:

interface IAuthOptions {
  authUrl: string; // Auth service url
  clientId: string; // Your service  client id
  clientSecret: string; // Your service client secret
  expirationLimitSeconds?: number; // if useCashe = true, defines a treshold between cached token expiraion, when new token will be retieved. 120 by default
  useCache?: boolean; // Sets if token caching is turned on. true by default
  httpRequestTimeout: number; // Sets http timeout for requests
  retryOptions: IAuthRetryOptions; // Allow to specify auth retry options
  logger?: IAuthLogger; // Allow to enable logging by specifying logger that would be used for logging internal diagnostics messages. Logging is disabled by default
  loggerMessagePrefix?: string; // Allow to specify custom logger messages prefix. "[tokiny] " by default
}
interface IAuthRetryOptions {
  retry: boolean // Should retry. Default false.
  retries?: number // The maximum amount of times to retry the operation. Default is 3.
  factor?: number // The exponential factor to use. Default is 2.
  minTimeout?: number // The number of milliseconds before starting the first retry. Default is 1000.
  maxTimeout?: number // The maximum number of milliseconds between two retries. Default is Infinity.
}
interface IAuthLogger {
  error: LogMethod
  warn: LogMethod
  info: LogMethod
  debug: LogMethod
}
type LogMethod = (msg: string | Error, err?: Error) => void

tokenFactory.getToken returns object of type ITokenSet:

export interface ITokenSet {
  access_token: string; //access_token itself
  expires_at: number; // token expiration time
  type: string; // token type
}

Tokiny also exports wrapped over http-fetch object, which expected by generated by nswag client for example. So you had not to set token to Authroization header manually. You can just write smth like this:

import {createTokenFactory, httpClientFactory} from "@targetprocess/tokiny";

const tokenFactory = createTokenFactory({
  authUrl: env.AUTH_SERVICE_URI,
  clientId: env.CLIENT_ID,
  clientSecret: env.CLIENT_SECRET
});

const token = await tokenFactory.getToken("scope1 scope2");
const scopes = "scope1 scope2";

const someClient = new SomeClient(
  `http://some_url`,
  httpClientFactory(scopes, tokenFactory, fetch)
);

Release notes

here