Skip to content

Commit

Permalink
add Readme v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Bassisto committed Nov 20, 2024
1 parent cb2df5d commit 9d49169
Showing 1 changed file with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,72 @@
# hydra-tools
# Hydra Client

A lightweight TypeScript client for handling OAuth2 token management with Hydra authentication server.

## Features

- Automatic token caching
- Token refresh management
- Configurable timeout settings
- Error handling with optional logging

## Usage
``` typescript
import { HydraClient, HydraConfig } from '@livechat/hydra-tools';


const config: HydraConfig = {
url: 'YOUR_HYDRA_URL',
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
timeout: 5000 // optional, defaults to 5000ms
};

const client = new HydraClient(config);

const authHeader = await client.getAuthHeaderForTarget('your-target');
```


## Configuration

The `HydraConfig` interface accepts the following parameters:


``` typescript
interface HydraConfig {
url: string; // Hydra server URL
clientId: string; // OAuth2 client ID
clientSecret: string; // OAuth2 client secret
timeout?: number; // Request timeout in milliseconds (default: 5000)
}
```


## Optional Logging

The client accepts an optional logger that implements the `HydraLogger` interface:

``` typescript
interface HydraLogger {
error: (obj: unknown, msg?: string, ...args: unknown[]) => void;
}
```
Usage with logger:

```typescript
const logger: HydraLogger = {
error: console.error
};
const client = new HydraClient(config, logger);
```

## Token Management

The client automatically handles:
- Token caching per target
- Automatic refresh after half of the token's lifetime
- Fallback to cached tokens during failed refresh attempts

## Internal Use Only

This package is intended for internal use within the organization. Please ensure proper handling of credentials and configuration values.

0 comments on commit 9d49169

Please sign in to comment.