npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sap-cf-axios

v1.0.2

Published

Wrap axios to use the SAP Cloud Foundry destination Service

Downloads

20,345

Readme

sap-cf-axios

Warning

This library is not an official SAP library, it is created by Flexso and free to use in your projects.
In case of any issues please create a github issue.

A library that creates an axios instance for destinations in SAP cloud foundry.

You can address destinations pointing to Internet and onPremise systems. The library will handle the authentication and proxy configuration.

If you want to connect with the current user (e.g. with principal propagation) just send the JWT token to the destination in the authorization header.

Installation

using npm:

$ npm install -s sap-cf-axios

Example

None, Basic or Oauth2ClientCredentials Authentication

The most simple example with a destination pointing to a service where we connect with fixed credentials. We do not need to send the current user with the request.

const SapCfAxios = require('sap-cf-axios').default;

const axios = SapCfAxios("<destinationName>");
axios({
    method: 'POST',
    url: '/BookSet',
    data: {
        title: "Using Axios in SAP Cloud Foundry",
        author: "Joachim Van Praet"
    },
    headers: {
        "content-type": "application/json"
    }
});

OAuth2SAMLDearerAssertion, OAuth2UserTokenExchange and Principal Propagation

For connecting to a destination as the current user, we send the current JWT token in the authorization header of the request.

    const SapCfAxios = require('sap-cf-axios').default;
    const axios = SapCfAxios("<destinationName>");
    
    var authorization = req.headers.authorization;
    
    const response = await axios({
            method: 'GET',
            url: '/iwfnd/catalogservice/',
            params: {
                "$format": 'json'
            },
            headers: {
                "content-type": "application/json",
                authorization 
            }
        });

NOTE: The JWT Token sent to the backend does not contain the properties name, login_name or mail. If you use principal propagation in the cloud connector you have to use ${email} or ${user_name} in the client certificate template

Handle X-CSRF-Token

To handle a POST request to for example CPI you can just set the name of the CSRF-Token header and the library will first do an OPTIONS call to the same URL to fetch the token and will add it to the request.

const SapCfAxios = require('sap-cf-axios').default;
const cpi = SapCfAxios("cpi_destination_name");

var authorization = req.headers.authorization;

const response = await cpi({
        method: 'POST',
        url: '/Bookset',
        headers: {
            "content-type": "application/json"
        },
            data: {
            title: "Using Axios in SAP Cloud Foundry",
            author: "Joachim Van Praet"
        }
        xsrfHeaderName: "x-csrf-token",
        data: {vatNumber},
    });

If you want to use another method or url for fetching the X-CSRF-Token. You can add this configuration as a third parameter to the constructor.

const SapCfAxios = require('sap-cf-axios').default;
const cpi = SapCfAxios( /* destination name */ "cpi_destination_name", /* axios default config */ null, /* xsrfConfig */ {method: 'get', url:'/'});

var authorization = req.headers.authorization;

const response = await cpi({
        method: 'POST',
        url: '/Bookset',
        headers: {
            "content-type": "application/json"
        },
            data: {
            title: "Using Axios in SAP Cloud Foundry",
            author: "Joachim Van Praet"
        }
        xsrfHeaderName: "x-csrf-token",
        data: {vatNumber},
    });