ts-keycloak-authentication

0.0.1 • Public • Published

ts-keycloak-authentication

Typescript Keycloak authentication package for handling internal service-to-service authentication within Fidel API services using Keycloak.

Installation

You can install the package using npm:

npm install @fidel.uk/ts-keycloak-authentication

Usage

import KeycloakAuthentication, {
  KeycloakAuthenticationConfig,
} from '@fidel.uk/ts-keycloak-authentication';
import { Log } from '@fidel.uk/ts-logger';

// Define your Keycloak configuration
const keycloakAuthenticationConfig: KeycloakAuthenticationConfig = {
  clientId: 'your-keycloak-client-id',
  clientSecret: 'your-keycloak-client-secret',
};

// Create an instance of the logger
const logger = new Log(/* your logger configuration */);

// Create an instance of the KeycloakAuthentication
const authentication = new KeycloakAuthentication(
  keycloakAuthenticationConfig,
  logger,
);

(async () => {
  try {
    const accessToken = await authentication.getAccessToken();
    // console.log("Access Token:", accessToken);
  } catch (error) {
    console.error('Authentication error:', error);
  }
})();

Configuration

The KeycloakAuthentication constructor supports an KeycloakAuthenticationConfig configuration object:

Parameter Type Required Description
clientId string yes The client ID for your Keycloak client.
clientSecret string yes The client secret for your Keycloak client.
keycloakUrl string no The URL of your Keycloak server. If not provided, it defaults to the stage-based URLs: "dev" - https://auth.platform.fidelapi.rocks; "prod" - https://auth.platform.fidelapi.com
realmName string no The realm name for your Keycloak setup. Defaults to "fidelapi".
stage string no The environment stage, either "dev" or "prod". Defaults to "prod".

Development

Install dependencies

  • Lint: npm ci

Lint

  • Lint: npm run lint
  • Fix: npm run prettier:fix

Test

  • Tests: npm run test
  • Tests with coverage: npm run test:coverage

Readme

Keywords

none

Package Sidebar

Install

npm i ts-keycloak-authentication

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

20.1 kB

Total Files

23

Last publish

Collaborators

  • fidel-api