Skip to content

Commit b35fbd8

Browse files
authored
chore: Add documentation for the transformServiceBindingToClientCredentialsDestination function (#1949)
1 parent d5ee826 commit b35fbd8

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

docs-js/features/connectivity/destination.mdx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,42 @@ The SAP Cloud SDK provides a default implementation for the transformation of se
200200

201201
The default implementation also retrieves a service token, if needed.
202202

203+
Additionally, we provide a function to transform service bindings into OAuth2ClientCredentials destinations, assuming the service binding follows the structure outlined below:
204+
205+
```json
206+
{
207+
"VCAP_SERVICES": {
208+
"custom-service": [
209+
{
210+
"name": "my-custom-service",
211+
"label": "custom-service",
212+
"tags": ["custom-service"],
213+
"url": "https://example.com",
214+
"credentials": {
215+
"clientid": "CLIENT_ID",
216+
"clientsecret": "CLIENT_SECRET"
217+
}
218+
}
219+
]
220+
}
221+
}
222+
```
223+
224+
If the service URL is not specified in the `url` property, it can alternatively be provided as part of the `options` parameter.
225+
226+
The following is a multi-tenant example, where the user's JWT is used for tenant-isolation in the cache together with a custom URL as target.
227+
228+
```ts
229+
const serviceBinding = getServiceBinding('custom-service');
230+
const userJwt = retrieveJwt(request);
231+
const destination = getDestinationFromServiceBinding({
232+
destinationName: 'custom-service',
233+
jwt: userJwt,
234+
useCache: true,
235+
transformServiceBindingToClientCredentialsDestination(serviceBinding, { url: 'custom-url', jwt: userJwt })
236+
})
237+
```
238+
203239
For other types of service bindings or if you want to overwrite the default behavior, provide a callback function (`serviceBindingTransformFn()`) in the request execution.
204240

205241
For example, if you have a binding for a custom service:
@@ -210,8 +246,8 @@ For example, if you have a binding for a custom service:
210246
"custom-service": [
211247
// This object is passed to `serviceBindingTransformFn()`
212248
{
213-
"label": "custom-service",
214249
"name": "my-custom-service",
250+
"label": "custom-service",
215251
"credentials": {
216252
"url": "https://example.com",
217253
"usr": "USERNAME",

0 commit comments

Comments
 (0)