Alokai
Basics

Protecting extension module with Basic Auth

The extension module is a public endpoint, so it must serve only the calls commercetools makes with your HTTP Basic credentials. The modules setup guide configures them from the start. If your API Extension was created without them, add them in the order below, so checkout keeps working during the change.

Prepare the credentials

Choose a username and a long random password, and get the Base64 form of username:password:

printf '%s' 'my-username:my-long-random-password' | base64

Send the credentials from commercetools

Update the API Extension first. An extension module without credentials in its configuration ignores the header, so payments keep working.

  1. Open API Playground,
  2. Make sure you've selected your desired project in the select input placed inside the page's header,
  3. Read the current version of the ctp-stripe-integration-payment-extension API Extension,
  4. Send the Change Destination update action to the Extensions endpoint for that key:
{
  "version": 1,
  "actions": [
    {
      "action": "changeDestination",
      "destination": {
        "type": "HTTP",
        "url": "URL_TO_YOUR_EXTENSION_MODULE_INSTANCE",
        "authentication": {
          "type": "AuthorizationHeader",
          "headerValue": "Basic ENCODED_BASE64_VALUE"
        }
      }
    }
  ]
}

Replace version with the current version of the API Extension, URL_TO_YOUR_EXTENSION_MODULE_INSTANCE with the URL where the extension module is available, and ENCODED_BASE64_VALUE with the value from the previous step.

Require the credentials in the extension module

Add the authentication property to the STRIPE_INTEGRATION_CONFIG environment variable of the extension module, with the same username and password:

{
  "stripe": {
    "stripeProfile1": {
      "secretKey": "sk_test_xxx"
    }
  },
  "authentication": {
    "enabled": true,
    "username": "my-username",
    "password": "my-long-random-password"
  },
  "logLevel": 20
}

Updating a configuration requires restart of application. From then on, the extension module answers 401 to a call without these credentials.

On this page