# SalesforceAuth (/docs/auth/api/classes/SalesforceAuth)



[@kysoql/auth](/docs/auth/api) / SalesforceAuth

Bound Salesforce OAuth client.

The class is the primary ergonomic API for applications. The standalone
functions remain exported for advanced composition and backwards
compatibility.

## Constructors [#constructors]

<a id="api-constructor" />

### Constructor [#constructor]

```ts
new SalesforceAuth(options): SalesforceAuth;
```

Creates a Salesforce authentication helper bound to a login URL and Connected App client ID.

#### Parameters [#parameters]

| Parameter | Type                                                                       |
| --------- | -------------------------------------------------------------------------- |
| `options` | [`SalesforceAuthOptions`](/docs/auth/api/interfaces/SalesforceAuthOptions) |

#### Returns [#returns]

`SalesforceAuth`

## Methods [#methods]

<a id="api-generatepkcepair" />

### generatePkcePair() [#generatepkcepair]

```ts
generatePkcePair(): Promise<PkcePair>;
```

Generate an RFC 7636 S256 verifier/challenge pair.

#### Returns [#returns-1]

`Promise`\<[`PkcePair`](/docs/auth/api/interfaces/PkcePair)>

***

<a id="api-authorizationurl" />

### authorizationUrl() [#authorizationurl]

```ts
authorizationUrl(options): string;
```

Build a standard OAuth authorization URL using this client's base config.

#### Parameters [#parameters-1]

| Parameter | Type                           |
| --------- | ------------------------------ |
| `options` | `BoundAuthorizationUrlOptions` |

#### Returns [#returns-2]

`string`

***

<a id="api-exchangeauthorizationcode" />

### exchangeAuthorizationCode() [#exchangeauthorizationcode]

```ts
exchangeAuthorizationCode(options): Promise<SalesforceOAuthSession>;
```

Exchange a standard authorization code.

#### Parameters [#parameters-2]

| Parameter | Type                            |
| --------- | ------------------------------- |
| `options` | `BoundAuthorizationCodeOptions` |

#### Returns [#returns-3]

`Promise`\<[`SalesforceOAuthSession`](/docs/auth/api/interfaces/SalesforceOAuthSession)>

***

<a id="api-exchangehybridauthorizationcode" />

### exchangeHybridAuthorizationCode() [#exchangehybridauthorizationcode]

```ts
exchangeHybridAuthorizationCode(options): Promise<SalesforceOAuthSession>;
```

Exchange a Salesforce hybrid-app authorization code.

#### Parameters [#parameters-3]

| Parameter | Type                            |
| --------- | ------------------------------- |
| `options` | `BoundAuthorizationCodeOptions` |

#### Returns [#returns-4]

`Promise`\<[`SalesforceOAuthSession`](/docs/auth/api/interfaces/SalesforceOAuthSession)>

***

<a id="api-refreshtoken" />

### refreshToken() [#refreshtoken]

```ts
refreshToken(options): Promise<SalesforceOAuthSession>;
```

Refresh a standard OAuth session.

#### Parameters [#parameters-4]

| Parameter | Type                       |
| --------- | -------------------------- |
| `options` | `BoundRefreshTokenOptions` |

#### Returns [#returns-5]

`Promise`\<[`SalesforceOAuthSession`](/docs/auth/api/interfaces/SalesforceOAuthSession)>

***

<a id="api-refreshhybridtoken" />

### refreshHybridToken() [#refreshhybridtoken]

```ts
refreshHybridToken(options): Promise<SalesforceOAuthSession>;
```

Refresh a Salesforce hybrid-app session.

#### Parameters [#parameters-5]

| Parameter | Type                       |
| --------- | -------------------------- |
| `options` | `BoundRefreshTokenOptions` |

#### Returns [#returns-6]

`Promise`\<[`SalesforceOAuthSession`](/docs/auth/api/interfaces/SalesforceOAuthSession)>

***

<a id="api-clientcredentials" />

### clientCredentials() [#clientcredentials]

```ts
clientCredentials(options): Promise<SalesforceOAuthSession>;
```

Authenticate a server integration with the client-credentials flow.

#### Parameters [#parameters-6]

| Parameter | Type                            |
| --------- | ------------------------------- |
| `options` | `BoundClientCredentialsOptions` |

#### Returns [#returns-7]

`Promise`\<[`SalesforceOAuthSession`](/docs/auth/api/interfaces/SalesforceOAuthSession)>

***

<a id="api-jwtbearer" />

### jwtBearer() [#jwtbearer]

```ts
jwtBearer(options): Promise<SalesforceOAuthSession>;
```

Authenticate the configured integration user with Salesforce JWT bearer.
The JWT assertion is created and exchanged in one call.

#### Parameters [#parameters-7]

| Parameter | Type                                                                                 |
| --------- | ------------------------------------------------------------------------------------ |
| `options` | [`SalesforceJwtBearerOptions`](/docs/auth/api/interfaces/SalesforceJwtBearerOptions) |

#### Returns [#returns-8]

`Promise`\<[`SalesforceOAuthSession`](/docs/auth/api/interfaces/SalesforceOAuthSession)>

***

<a id="api-createclientassertion" />

### createClientAssertion() [#createclientassertion]

```ts
createClientAssertion(options): Promise<string>;
```

Create a private\_key\_jwt assertion for a later token request.

#### Parameters [#parameters-8]

| Parameter | Type                                                                                               |
| --------- | -------------------------------------------------------------------------------------------------- |
| `options` | [`SalesforceClientAssertionOptions`](/docs/auth/api/type-aliases/SalesforceClientAssertionOptions) |

#### Returns [#returns-9]

`Promise`\<`string`>

***

<a id="api-samlbearer" />

### samlBearer() [#samlbearer]

```ts
samlBearer(options): Promise<SalesforceOAuthSession>;
```

Exchange a SAML 2.0 bearer assertion.

#### Parameters [#parameters-9]

| Parameter | Type                     |
| --------- | ------------------------ |
| `options` | `BoundSamlBearerOptions` |

#### Returns [#returns-10]

`Promise`\<[`SalesforceOAuthSession`](/docs/auth/api/interfaces/SalesforceOAuthSession)>

***

<a id="api-samlassertion" />

### samlAssertion() [#samlassertion]

```ts
samlAssertion(options): Promise<SalesforceOAuthSession>;
```

Exchange a Salesforce SAML assertion for API access.

#### Parameters [#parameters-10]

| Parameter | Type                        |
| --------- | --------------------------- |
| `options` | `BoundSamlAssertionOptions` |

#### Returns [#returns-11]

`Promise`\<[`SalesforceOAuthSession`](/docs/auth/api/interfaces/SalesforceOAuthSession)>

***

<a id="api-tokenexchange" />

### tokenExchange() [#tokenexchange]

```ts
tokenExchange(options): Promise<SalesforceOAuthSession>;
```

Exchange a supported subject token through Salesforce OAuth token exchange.

#### Parameters [#parameters-11]

| Parameter | Type                        |
| --------- | --------------------------- |
| `options` | `BoundTokenExchangeOptions` |

#### Returns [#returns-12]

`Promise`\<[`SalesforceOAuthSession`](/docs/auth/api/interfaces/SalesforceOAuthSession)>

***

<a id="api-requestdeviceauthorization" />

### requestDeviceAuthorization() [#requestdeviceauthorization]

```ts
requestDeviceAuthorization(options?): Promise<DeviceAuthorization>;
```

Start the device authorization flow.

#### Parameters [#parameters-12]

| Parameter | Type                              |
| --------- | --------------------------------- |
| `options` | `BoundDeviceAuthorizationOptions` |

#### Returns [#returns-13]

`Promise`\<[`DeviceAuthorization`](/docs/auth/api/interfaces/DeviceAuthorization)>

***

<a id="api-polldeviceauthorization" />

### pollDeviceAuthorization() [#polldeviceauthorization]

```ts
pollDeviceAuthorization(options): Promise<SalesforceOAuthSession>;
```

Perform one device-flow polling exchange.

#### Parameters [#parameters-13]

| Parameter | Type                      |
| --------- | ------------------------- |
| `options` | `BoundDeviceTokenOptions` |

#### Returns [#returns-14]

`Promise`\<[`SalesforceOAuthSession`](/docs/auth/api/interfaces/SalesforceOAuthSession)>

***

<a id="api-codecredentialsauthorization" />

### codeCredentialsAuthorization() [#codecredentialsauthorization]

```ts
codeCredentialsAuthorization(options): HeadlessAuthorizationRequest;
```

Build an Experience Cloud Authorization Code and Credentials request.

#### Parameters [#parameters-14]

| Parameter | Type                                       |
| --------- | ------------------------------------------ |
| `options` | `BoundCodeCredentialsAuthorizationOptions` |

#### Returns [#returns-15]

[`HeadlessAuthorizationRequest`](/docs/auth/api/interfaces/HeadlessAuthorizationRequest)

***

<a id="api-guestauthorization" />

### guestAuthorization() [#guestauthorization]

```ts
guestAuthorization(options): HeadlessAuthorizationRequest;
```

Build the Experience Cloud guest Code and Credentials request.

#### Parameters [#parameters-15]

| Parameter | Type                                     |
| --------- | ---------------------------------------- |
| `options` | `BoundHeadlessGuestAuthorizationOptions` |

#### Returns [#returns-16]

[`HeadlessAuthorizationRequest`](/docs/auth/api/interfaces/HeadlessAuthorizationRequest)

***

<a id="api-firstpartyauthorizationchallenge" />

### firstPartyAuthorizationChallenge() [#firstpartyauthorizationchallenge]

```ts
firstPartyAuthorizationChallenge(options): Promise<FirstPartyAuthorizationChallenge>;
```

Call OAuth 2.0 for First-Party Applications authorization\_challenge.

#### Parameters [#parameters-16]

| Parameter | Type                                           |
| --------- | ---------------------------------------------- |
| `options` | `BoundFirstPartyAuthorizationChallengeOptions` |

#### Returns [#returns-17]

`Promise`\<[`FirstPartyAuthorizationChallenge`](/docs/auth/api/type-aliases/FirstPartyAuthorizationChallenge)>

***

<a id="api-storedrefreshtoken" />

### storedRefreshToken() [#storedrefreshtoken]

```ts
storedRefreshToken(options): StoredRefreshTokenAuth;
```

Create a refresh-token-backed session manager bound to this client.

#### Parameters [#parameters-17]

| Parameter | Type                                 |
| --------- | ------------------------------------ |
| `options` | `BoundStoredRefreshTokenAuthOptions` |

#### Returns [#returns-18]

[`StoredRefreshTokenAuth`](/docs/auth/api/interfaces/StoredRefreshTokenAuth)

## Properties [#properties]

| Property                                    | Modifier   | Type     | Description                                   |
| ------------------------------------------- | ---------- | -------- | --------------------------------------------- |
| <a id="api-property-loginurl" /> `loginUrl` | `readonly` | `string` | Salesforce login or My Domain base URL.       |
| <a id="api-property-clientid" /> `clientId` | `readonly` | `string` | Connected App consumer key / OAuth client ID. |
