@cmdbg/tokenator
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Build Status

tokenator

Simple HTTP library to get tokens from 3rd party identity providers

Usage

import {
  AuthConfig,
  AadAuthenticationClient,
  Token,
  TokenError,
} from '@cmdbg/tokenator';

export class AadRopcStrategy {

  async getAccessToken(payload: AuthConfig): Promise<string> {
    const authConfig = {
      clientID: payload.clientID,
      clientSecret: payload.clientSecret,
      tenant: payload.tenant,
      scope: payload.scope,
      username: payload.username,
      password: payload.password,
    };

    const authClient = new AadAuthenticationClient(() => authConfig);
    const res = await authClient.authenticateROPC();
    const token = res as Token;

    if (token) return token.access_token;

    const err = res as TokenError;
    throw new Error(err.error_description);
  }
}

Package Sidebar

Install

npm i @cmdbg/tokenator

Weekly Downloads

5

Version

0.1.1

License

MIT

Unpacked Size

19.2 kB

Total Files

36

Last publish

Collaborators

  • vyanakiev