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

[@salesforce/b2c-tooling-sdk](../../modules.md) / [clients](../index.md) / createAuthMiddleware

# Function: createAuthMiddleware()

> **createAuthMiddleware**(`auth`): `Middleware`

Defined in: [packages/b2c-tooling-sdk/src/clients/middleware.ts:57](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/clients/middleware.ts#L57)

Creates authentication middleware for openapi-fetch.

This middleware intercepts requests and adds OAuth authentication headers
using the provided AuthStrategy. It also handles 401 responses by invalidating
the token and retrying the request once with a fresh token.

## Parameters

### auth

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

The authentication strategy to use

## Returns

`Middleware`

Middleware that adds auth headers to requests and retries on 401
