---
editLink: false
lastUpdated: false
---

[@salesforce/b2c-tooling-sdk](../../modules.md) / [auth](../index.md) / StatefulOAuthStrategy

# Class: StatefulOAuthStrategy

Defined in: [packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts:43](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts#L43)

Auth strategy that uses a persisted access token from the unified store.
No refresh — on expiry/401, the session is cleared and the caller is
expected to re-authenticate.

## Implements

- [`AuthStrategy`](../interfaces/AuthStrategy.md)

## Constructors

### Constructor

> **new StatefulOAuthStrategy**(`session`, `options`): `StatefulOAuthStrategy`

Defined in: [packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts:48](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts#L48)

#### Parameters

##### session

[`AuthSession`](../interfaces/AuthSession.md)

##### options

[`StatefulOAuthStrategyOptions`](../interfaces/StatefulOAuthStrategyOptions.md)

#### Returns

`StatefulOAuthStrategy`

## Methods

### fetch()

> **fetch**(`url`, `init`): `Promise`\<`Response`\>

Defined in: [packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts:53](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts#L53)

Performs a fetch request with authentication.
Implementations MUST handle header injection and 401 retries (token refresh) internally.

#### Parameters

##### url

`string`

##### init

[`FetchInit`](../type-aliases/FetchInit.md) = `{}`

#### Returns

`Promise`\<`Response`\>

#### Implementation of

[`AuthStrategy`](../interfaces/AuthStrategy.md).[`fetch`](../interfaces/AuthStrategy.md#fetch)

***

### getAuthorizationHeader()

> **getAuthorizationHeader**(): `Promise`\<`string`\>

Defined in: [packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts:77](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts#L77)

Optional: Helper for legacy clients (like a strict WebDAV lib) that need the raw header.

#### Returns

`Promise`\<`string`\>

#### Implementation of

[`AuthStrategy`](../interfaces/AuthStrategy.md).[`getAuthorizationHeader`](../interfaces/AuthStrategy.md#getauthorizationheader)

***

### getJWT()

> **getJWT**(): `Promise`\<[`DecodedJWT`](../interfaces/DecodedJWT.md)\>

Defined in: [packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts:90](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts#L90)

#### Returns

`Promise`\<[`DecodedJWT`](../interfaces/DecodedJWT.md)\>

***

### getTokenResponse()

> **getTokenResponse**(): `Promise`\<[`AccessTokenResponse`](../interfaces/AccessTokenResponse.md)\>

Defined in: [packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts:84](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts#L84)

Returns the current token as AccessTokenResponse (expires/scopes from JWT).

#### Returns

`Promise`\<[`AccessTokenResponse`](../interfaces/AccessTokenResponse.md)\>

***

### invalidateToken()

> **invalidateToken**(): `void`

Defined in: [packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts:94](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/auth/stateful-oauth-strategy.ts#L94)

Optional: Invalidates the cached token, forcing re-authentication on next request.
Used by middleware to retry requests after receiving a 401 response.

#### Returns

`void`

#### Implementation of

[`AuthStrategy`](../interfaces/AuthStrategy.md).[`invalidateToken`](../interfaces/AuthStrategy.md#invalidatetoken)
