# Providers

## Creating a Provider

It's incredibly simple to create a custom provider!

{% hint style="info" %}
We highly recommend you write your Provider in TypeScript to take advantage of our documentation!
{% endhint %}

{% tabs %}
{% tab title="TypeScript" %}

```typescript
// my-custom-provider.ts
import { OpenIDProvider } from '@salte-auth/salte-auth';

export class Auth0 extends OpenIDProvider {
  constructor(config: Auth0.Config) {
    super(config);
  }

  /**
   * This is the default name of the provider.
   */
  get name() {
    return 'auth0';
  }

  /**
   * This should use `this.config.url` to build the provider-specific login url.
   */
  get login() {
    // In this case Auth0's "/authorize" is right at the root and 
    // it supports a custom audience parameter.
    return this.url(`${this.config.url}/authorize`, {
      audience: this.config.audience
    });
  }

  /**
   * This should use `this.config.url` to build the provider-specific logout url.
   */
  get logout() {
    return this.url(`${this.config.url}/v2/logout`, {
      returnTo: this.config.redirectUrl,
      client_id: this.config.clientID
    });
  }
}

export interface Auth0 {
  config: Auth0.Config;
}

export declare namespace Auth0 {
  export interface Config extends OpenIDProvider.Config {
    audience?: string
  }
}
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
// my-custom-provider.js
import { OpenIDProvider } from '@salte-auth/salte-auth';

export class CustomProvider extends OpenIDProvider {
  /**
   * This is the default name of the provider.
   */
  get name() {
    return 'auth0';
  }

  /**
   * This should use `this.config.url` to build the provider-specific login url.
   */
  get login() {
    // In this case Auth0's "/authorize" is right at the root and 
    // it supports a custom audience parameter.
    return this.url(`${this.config.url}/authorize`, {
      audience: this.config.audience
    });
  }

  /**
   * This should use `this.config.url` to build the provider-specific logout url.
   */
  get logout() {
    return this.url(`${this.config.url}/v2/logout`, {
      returnTo: this.config.redirectUrl,
      client_id: this.config.clientID
    });
  }
}
```

{% endtab %}
{% endtabs %}

## Using your Custom Provider

It's equally as easy to use a custom provider.

```javascript
import { SalteAuth } from '@salte-auth/salte-auth';
import { Tab } from '@salte-auth/tab';
import { CustomProvider } from './my-custom-provider.js';

const auth = new SalteAuth({
  // ...

  providers: [
    new CustomProvider({
      url: 'https://salte-os.auth0.com',
      clientID: '9JTBXBREtckkFHTxTNBceewrnn7NeDd0'
    })
  ],

  handlers: [
    new Tab({
      default: true
    })
  ]
});

auth0.login('auth0');
```


---

# Agent Instructions: 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:

```
GET https://salte-auth.gitbook.io/salte-auth/extending/providers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
