> Documentation index: https://www.gooddata.ai/docs/gooddata-ui/llms.txt lists every page of these docs as Markdown.

# IAuthenticationProvider

- Package: [@gooddata/sdk-backend-spi](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/index.md)
- Kind: interface
- Source: https://github.com/gooddata/gooddata-ui-sdk/blob/rel/11.64/libs/sdk-backend-spi/src/backend/index.ts

Defines authentication provider to use when instance of [IAnalyticalBackend](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.ianalyticalbackend/index.md) discovers that the current session is not authentication.

**Signature:**

```typescript
export interface IAuthenticationProvider 
```

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [disablePrincipalCache](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.iauthenticationprovider/index.md#iauthenticationproviderdisableprincipalcache) |  | boolean | Instructs the consumer which uses this provider to not cache authentication in any ways. Note: It does not affect calls deduplication like debouncing or throttling. If true, the consumer will always call authenticate if there is a need to authenticate user (like if some request respons with 401). If false, the consumer is allowed to cache the authenticated principal and reuse it for subsequent requests. This is the current behavior. It is here because some implementations of authentication works with time restricted sessions. It means the session can expire during user activity and the consumer should call authenticate again and not just reuse the cached principal. FIXME: I believe this should be true by default and if authentication provider wants to do some caching, it should implement it on its own. In this case, this property should be removed from the interface. But for now I dont have enough time to refactor this, so Im creating this backwards compatible solution. See JIRA ticket F1-1256 for more details. |
| [onNotAuthenticated?](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.iauthenticationprovider/index.md#iauthenticationprovideronnotauthenticated) |  | [NotAuthenticatedHandler](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.notauthenticatedhandler/index.md) | _(Optional)_ Specify function to be called when the Analytical Backend raises a [NotAuthenticated](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.notauthenticated/index.md) error. |

## Methods

| Method | Description |
| --- | --- |
| [authenticate(context)](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.iauthenticationprovider/index.md#iauthenticationproviderauthenticate) | Perform authentication. |
| [deauthenticate(context, returnTo)](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.iauthenticationprovider/index.md#iauthenticationproviderdeauthenticate) | Clear existing authentication. |
| [getCurrentPrincipal(context)](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.iauthenticationprovider/index.md#iauthenticationprovidergetcurrentprincipal) | Returns the currently authenticated principal, or undefined if not authenticated. Does not trigger authentication if no principal is available. |
| [initializeClient(client)?](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.iauthenticationprovider/index.md#iauthenticationproviderinitializeclient) | _(Optional)_ Perform custom initialization of the client that the Analytical Backend uses to communicate with the server. |

## Property details

### IAuthenticationProvider.disablePrincipalCache

Instructs the consumer which uses this provider to not cache authentication in any ways. Note: It does not affect calls deduplication like debouncing or throttling.

If true, the consumer will always call authenticate if there is a need to authenticate user (like if some request respons with 401). If false, the consumer is allowed to cache the authenticated principal and reuse it for subsequent requests. This is the current behavior.

It is here because some implementations of authentication works with time restricted sessions. It means the session can expire during user activity and the consumer should call authenticate again and not just reuse the cached principal.

FIXME: I believe this should be true by default and if authentication provider wants to do some caching, it should implement it on its own. In this case, this property should be removed from the interface. But for now I dont have enough time to refactor this, so Im creating this backwards compatible solution. See JIRA ticket F1-1256 for more details.

**Signature:**

```typescript
disablePrincipalCache: boolean;
```

### IAuthenticationProvider.onNotAuthenticated

Specify function to be called when the Analytical Backend raises a [NotAuthenticated](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.notauthenticated/index.md) error.

**Signature:**

```typescript
onNotAuthenticated?: NotAuthenticatedHandler;
```

## Method details

### IAuthenticationProvider.authenticate()

Perform authentication.

**Signature:**

```typescript
authenticate(context: IAuthenticationContext): Promise<IAuthenticatedPrincipal>;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| context | [IAuthenticationContext](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.iauthenticationcontext/index.md) | context in which the authentication is done |

**Returns:**

Promise&lt;[IAuthenticatedPrincipal](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.iauthenticatedprincipal/index.md)&gt;

### IAuthenticationProvider.deauthenticate()

Clear existing authentication.

**Signature:**

```typescript
deauthenticate(context: IAuthenticationContext, returnTo?: string): Promise<void>;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| context | [IAuthenticationContext](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.iauthenticationcontext/index.md) | context in which the authentication is done |
| returnTo | string | _(Optional)_ url to redirect after successful logout |

**Returns:**

Promise&lt;void&gt;

### IAuthenticationProvider.getCurrentPrincipal()

Returns the currently authenticated principal, or undefined if not authenticated. Does not trigger authentication if no principal is available.

**Signature:**

```typescript
getCurrentPrincipal(context: IAuthenticationContext): Promise<IAuthenticatedPrincipal | null>;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| context | [IAuthenticationContext](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.iauthenticationcontext/index.md) |  |

**Returns:**

Promise&lt;[IAuthenticatedPrincipal](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-backend-spi/sdk-backend-spi.iauthenticatedprincipal/index.md) &#124; null&gt;

### IAuthenticationProvider.initializeClient()

Perform custom initialization of the client that the Analytical Backend uses to communicate with the server.

**Signature:**

```typescript
initializeClient?(client: any): void;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| client | any | an instance of client |

**Returns:**

void

#### Remarks

If implemented, this function WILL BE called by the backend every time a new instance of API client is created.

Note: the configuration and construction of Analytical Backend instance is cumulative. Backend implementations MAY create multiple instances of clients during construction.
