Skip to content

Commit dff9d71

Browse files
committed
chore: [js] Document IAS token and destination helper functions
1 parent 9171f9e commit dff9d71

2 files changed

Lines changed: 68 additions & 6 deletions

File tree

docs-js/features/connectivity/destination.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ Note, that if your `serviceBindingTransformFn()` function does not provide a nam
275275

276276
More advanced examples with service token fetching can be found in [service-binding-to-destination.ts](https://github.com/SAP/cloud-sdk-js/blob/main/packages/connectivity/src/scp-cf/destination/service-binding-to-destination.ts).
277277

278+
For the `identity` service type, the SAP Cloud SDK also provides the standalone convenience functions `getIasToken()` and `getIasDestination()`, which can also work with bare `ServiceCredentials` outside of a `VCAP_SERVICES` binding.
279+
See the [Identity Authentication Service](./ias#convenience-functions) documentation for details.
280+
278281
If you want to skip the destination lookup and consider only the service bindings, call the [getDestinationFromServiceBinding()](pathname:///api/v4/functions/sap-cloud-sdk_connectivity.getDestinationFromServiceBinding.html) function with the service name and options.
279282

280283
```ts

docs-js/features/connectivity/ias.mdx

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@ sequenceDiagram
8181

8282
### Creating Destinations
8383

84-
Use [`getDestinationFromServiceBinding()`](pathname:///api/v4/functions/sap-cloud-sdk_connectivity.getDestinationFromServiceBinding.html) to connect to a system that is registered as an application within IAS.
84+
Use [`getDestinationFromServiceBinding()`](pathname:///api/v4/functions/sap-cloud-sdk_connectivity.getDestinationFromServiceBinding.html) or [`transformServiceBindingToDestination()`](pathname:///api/v4/functions/sap-cloud-sdk_connectivity.transformServiceBindingToDestination.html) to connect to a system that is registered as an application within IAS.
8585
The parameter `iasOptions` contains:
8686

8787
- `targetUrl`: The URL of the system where the target application resides.
8888
- `resource`: The dependency identified by its name or identifier configured in IAS (see [App2App Resources](#app2app-resources)) section.
8989

90+
In addition to these standard functions for destination retrieval and transformation, the SAP Cloud SDK provides two convenience functions, [`getIasDestination()`](pathname:///api/v4/functions/sap-cloud-sdk_connectivity.getIasDestination.html) and [`getIasToken()`](pathname:///api/v4/functions/sap-cloud-sdk_connectivity.getIasToken.html), which fetch an IAS token and return a destination or token result respectively.
91+
These functions are useful when you need direct access to the IAS token or destination, for example outside BTP environments with pre-populated `VCAP_SERVICES` or when constructing a destination manually.
92+
Refer to the [Convenience Functions](#convenience-functions) section below for more details.
93+
9094
#### Technical User Authentication
9195

9296
For service-to-service communication with client credentials:
@@ -121,11 +125,6 @@ const destination = await getDestinationFromServiceBinding({
121125

122126
#### Business User Authentication
123127

124-
:::warning
125-
126-
When using business user authentication, token requests are not cached.
127-
128-
:::
129128
:::info
130129

131130
Setting `authenticationType` to `OAuth2JWTBearer` is required to trigger Business User authentication.
@@ -246,3 +245,63 @@ const destination = await getDestinationFromServiceBinding({
246245
});
247246
// Token request is automatically routed to the subscriber's IAS tenant
248247
```
248+
249+
## Convenience Functions
250+
251+
The SAP Cloud SDK provides two convenience functions for working with IAS tokens directly.
252+
These are useful when you need access to the IAS token or destination, for example outside BTP environments with pre-populated `VCAP_SERVICES` or when constructing a destination manually.
253+
254+
Both functions accept a service as `Service | string | ServiceCredentials`, unlike `getDestinationFromServiceBinding()` they also accept bare `ServiceCredentials` (e.g., just `clientid`, `clientsecret`, and `url`).
255+
256+
- **[`getIasDestination()`](pathname:///api/v4/functions/sap-cloud-sdk_connectivity.getIasDestination.html)** fetches an IAS token and builds a ready-to-use [`Destination`](pathname:///api/v4/interfaces/sap-cloud-sdk_connectivity.Destination.html) with the token, the target URL, and the mTLS key pair from the service binding credentials (if present).
257+
- **[`getIasToken()`](pathname:///api/v4/functions/sap-cloud-sdk_connectivity.getIasToken.html)** fetches an IAS token and returns an [`IasTokenResult`](pathname:///api/v4/interfaces/sap-cloud-sdk_connectivity.IasTokenResult.html) with the access token string, its expiration, and an optional refresh token.
258+
259+
:::note
260+
261+
`getIasToken()` returns the access token as a raw string rather than a decoded JWT, as IAS tokens may not always be in JWT format.
262+
263+
:::
264+
265+
:::note
266+
267+
The `targetUrl` is ignored if `getIasToken()` is used.
268+
269+
:::
270+
271+
```typescript
272+
import { getIasDestination, getIasToken } from '@sap-cloud-sdk/connectivity';
273+
274+
// Use getIasDestination() to build a destination (technical user)
275+
const destination = await getIasDestination(
276+
{
277+
clientid: 'CLIENT_ID',
278+
clientsecret: 'CLIENT_SECRET',
279+
url: 'https://my-ias.accounts.ondemand.com'
280+
},
281+
{
282+
targetUrl: 'https://backend-provider.example.com',
283+
jwt: JWT_PAYLOAD,
284+
requestAs: 'current-tenant',
285+
resource: { name: 'backend-api' }
286+
}
287+
);
288+
289+
// Use getIasToken() to retrieve an IAS token (business user)
290+
const token = await getIasToken(
291+
{
292+
clientid: 'CLIENT_ID',
293+
clientsecret: 'CLIENT_SECRET',
294+
url: 'https://my-ias.accounts.ondemand.com'
295+
},
296+
{
297+
authenticationType: 'OAuth2JWTBearer',
298+
assertion: JWT_ASSERTION,
299+
resource: { name: 'backend-api' }
300+
}
301+
);
302+
```
303+
304+
The `Destination` returned by `getIasDestination()` can be passed directly to any SAP Cloud SDK request builder or HTTP client.
305+
306+
For the full set of options both functions accept the same [`IasTokenOptions`](pathname:///api/v4/types/sap-cloud-sdk_connectivity.IasTokenOptions.html) which includes `iasOptions` properties as available in [`getDestinationFromServiceBinding()`](pathname:///api/v4/functions/sap-cloud-sdk_connectivity.getDestinationFromServiceBinding.html) or [`transformServiceBindingToDestination()`](pathname:///api/v4/functions/sap-cloud-sdk_connectivity.transformServiceBindingToDestination.html).
307+
See the [App2App Authentication](#app2app-authentication) section above for details.

0 commit comments

Comments
 (0)