> For the complete documentation index, see [llms.txt](https://kbase.whitelabel-loyalty.com/developer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kbase.whitelabel-loyalty.com/developer/resources/typescript-sdk/authentication.md).

# Authentication

{% hint style="info" %}
This page describes the authentication methods used by White Label Loyalty (WLL) services:

* "Admin Authentication" — a WLL-issued administrator token.
* "Tenant Authentication" — a token typically issued by your system for end users.

In this guide, **Admin Authentication** refers to a WLL-issued admin token and **Tenant Authentication** refers to a token issued for an end user to use.
{% endhint %}

{% tabs %}
{% tab title="Admin Authentication" %}
Admin authentication is provided via the `AdminAuthProvider`.

```ts
import { AdminAuthProvider } from '@wll-sdk/api';
```

Example: initializing the WLL Rewards SDK with an `AdminAuthProvider`

{% code title="admin.ts" %}

```ts
import { WLLRewardsSdk, AdminAuthProvider } from '@wll-sdk/api';

new WLLRewardsSdk({
  apiKey: '<your-api-key>',
  authProvider: new AdminAuthProvider({
    clientId: '<your-client-id>',
    clientSecret: '<your-client-secret>',
  }),
  baseUrl: 'https://api.rewards.wlloyalty.net/v1',
});
```

{% endcode %}

The `AdminAuthProvider` will automatically extract which region you are using from the `baseUrl` and attempt to authenticate. Current regions supported by the SDK:

* EU
* US

AdminAuthConfig Reference

| Property       | type      | Required? |
| -------------- | --------- | --------- |
| `clientId`     | `string`  | Y         |
| `clientSecret` | `string`  | Y         |
| `grantType`    | `string?` | N         |
| `audience`     | `string?` | N         |
| `scope`        | `string?` | N         |
| {% endtab %}   |           |           |

{% tab title="Tenant (Static) Authentication" %}
Tenant authentication is provided via the `StaticAuthProvider`.

```ts
import { StaticAuthProvider } from '@wll-sdk/api';
```

The `StaticAuthProvider` is a simple implementation of `AuthProvider` that takes a token in its constructor and always returns that token. It is useful for tenant authentication after completing your authentication flow, or for admin authentication if you store an admin token.

Example: initializing the WLL Rewards SDK with a `StaticAuthProvider`

{% code title="tenant.ts" %}

```ts
import { WLLRewardsSdk, StaticAuthProvider } from '@wll-sdk/api';

async function tenantTokenFlow(): Promise<string> {
  // Your implementation.
}

const token = await tenantTokenFlow();

new WLLRewardsSdk({
  apiKey: '<your-api-key>',
  authProvider: new StaticAuthProvider({
    token,
  }),
  baseUrl: 'https://api.rewards.wlloyalty.net/v1',
});
```

{% endcode %}

StaticAuthConfig Reference

| Property     | type     | Required? |
| ------------ | -------- | --------- |
| `token`      | `string` | Y         |
| {% endtab %} |          |           |

{% tab title="Custom AuthProvider (Implement your own)" %}
If needed, implement your own `AuthProvider`. The abstract class `AuthProvider` is exported by the SDK. Implementing it lets you pass a custom provider to the SDK (for example, fetching a token from a remote cache).

Abstract method signature:

```ts
abstract class AuthProvider {
  public abstract getToken(region: Region): Promise<string>;
}
```

Example: minimal custom auth provider

{% code title="remote-auth-provider.ts" %}

```ts
import { WLLRewardsSdk, AuthProvider } from '@wll-sdk/api';
import { fetchRemoteToken } from '../path/to/fetchRemoteToken';

class RemoteAuthProvider implements AuthProvider {
  public async getToken(region: any): Promise<string> {
    const token = await fetchRemoteToken();
    return token;
  }
}

new WLLRewardsSdk({
  apiKey: '<your-api-key>',
  authProvider: new RemoteAuthProvider(),
  baseUrl: 'https://api.rewards.wlloyalty.net/v1',
});
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://kbase.whitelabel-loyalty.com/developer/resources/typescript-sdk/authentication.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
