neo
environment in SAP Cloud Platform, a so-called destination
enables proxying HTTP
requests at runtime. This not only fullfilled CORS
requirements in a browser-based scenario, but also allowed querying data in a SAPCP-application from an on-premise system.destination
is the same in the SAP CP Cloud Foundry (cf)
environment, it's usage is completely different. Let's elaborate.destinations
are of substantical value in hybrid application architectures, where a cloud application wants to retrieve data from an on-premise system via the Cloud Connector.neo
, callinghttps://myapp-4711.dispatcher.hana.ondemand.com/⮐
destinations/<destination-name>/path/to/resource
/path/to/resource
on the server configured in <destination-name>
(can be an on-premise system!) to the application running on https://myapp-4711.dispatcher.hana.ondemand.com
- a really convenient way to proxy requests fullfilling CORS requirements.cf
, it's necessary todestination
(sub-account level)destination
instance (space level)connectivity
instance (space level)xsuaa
instance (space level)connectivity
instance serves as a generic reverse proxy, where as the destination
instance is nothing more but a catalogue organizing proxy targets (including on-premise systems).xsuaa
instance serves as the credentials authority, issuing JWT
(via `OAuth 2.0) to allowdestination
instance for an entryconnectivity
instance) for actually proxying requestscf
:xsuaa
instance for using the destination
instancedestination
instancexsuaa
instance for using the reverse proxy (aka connectivity
instance)<uri>
in the destinationnodejs
)destinations
/connectivity
in nodejs
:cf
along with services, bindings and instances nicely, but also doesn't mention any proxying and is difficult to re-usesap-cf-destination
(super alpha pre-release, yada yada).Java
implementation at https://help.sap.com/viewer/cca91383641e40ffbe03bdc78f00f681/Cloud/en-US/313b215066a8400db461b311e01... and ported it to a reusable node
module in JavaScript
.const callDestination = require('sap-cf-destination');
callDestination({
// url to call on proxied server
url: '/api/json',
// name of the CF connectivity service instance
connectivity_instance: 'connectivity-lite',
// name of the CF xsuaa service instance
uaa_instance: 'uaa-lite',
// name of the CF destination service instance
destination_instance: 'destination-lite',
// name of the configured destination
destination_name: 'my_destination'
})
.then(response => {
// do sth clever from the response
// of $server_behind_destination_'my_destination'/api/json
})
.catch(err => {
// oh no ?
})
OAuth 2.0
client is used for retrieving tokens from both connectivity- and destination-instance, wrapped in a Promise
:new Promise((resolve, reject) => {
const oAuthClient = new OAuth2(
<either destination or connectivity client id>,
<either destination or connectivity client secret>,
<url of cf xsuaa instance>,
'/oauth/authorize', // authorization endpoint
'oauth/token', // token issuer endpoint
null // no custom headers
);
oAuthClient.getOAuthAccessToken(
'',
{grant_type: 'client_credentials'},
(err, accessToken, refreshToken, results) => {
if (err) {
reject(err);
}
resolve(accessToken);
}
);
});
cf
proxy is done via the npm request-promise
http client module:const proxy = `http://${connectivityInstance.credentials.onpremise_proxy_host}:
${connectivityInstance.credentials.onpremise_proxy_port}`;
const options = {
url: <destination api/destination>,
method: 'GET',
headers: <proxy access token>,
proxy: proxy
};
request(options);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |