Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
"--runInBand"
],
"console": "externalTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
}
]
"version": "0.2.0",
"configurations": [
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
"--runInBand"
],
"console": "externalTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
},
{
"name": "Debug Jest Test (selected file)",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect",
"${workspaceRoot}/node_modules/.bin/jest",
"--runInBand",
"--no-cache",
"--detectOpenHandles",
"${fileBasenameNoExtension}"
],
"console": "integratedTerminal",
"sourceMaps": true,
"outputCapture": "std" // provide winston messages too
}
]
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ const client = new AlertNotificationClient({
region: RegionUtils.EU10;
});


// Or with a destinationName
const client = new AlertNotificationClient({
authentication: new DestinationAuthentification({
destinationName: 'myWonderfulDestination'
}),
region: RegionUtils.EU10;
});

// After that you can use the provided methods from the Alert Notification service instance
```

Expand Down
28 changes: 28 additions & 0 deletions __tests__/authentication.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios, { AxiosRequestConfig } from 'axios';
import {
BasicAuthentication,
DestinationAuthentication,
CertificateAuthentication,
OAuthAuthentication
} from '../src/authentication';
Expand Down Expand Up @@ -37,6 +38,33 @@ describe('BasicAuthentication', () => {
});
});

// Fake a destination to be existing locally
process.env.destinations = JSON.stringify([{
"URL": "https://destination.example.com",
"Name": "localDestination",
"Authentication": "BasicAuthentication",
"User": "username",
"Password": "password",
"Type": "HTTP",
"ProxyType": "Internet"
}]);

describe('DestinationAuthentication', () => {
test('can be correctly instantiated', () => {
expect(new DestinationAuthentication("localDestination")).toBeDefined();
});

test('when getAuthorizationHeaderValue is called then correct value is returned', () => {
const expectedValue = `Basic ${Buffer.from(
`${basicCredentials.username}:${basicCredentials.password}`
).toString('base64')}`;
return new DestinationAuthentication("localDestination")
.getAuthorizationHeaderValue()
.then((actualValue) => expect(actualValue).toBe(expectedValue));
});
});


describe('OAuthAuthentication', () => {
let oauthResponse: { data: { access_token: string; expires_in: number } };

Expand Down
16 changes: 16 additions & 0 deletions docs/_data/destination-authentication.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"propertyFields": [
{
"name": "destinationName",
"type": "string",
"description": "The name of the destination configured on your bound destination-service instance"
}
],
"methods": [
{
"name": "getAuthorizationHeaderValue()",
"returnValue": "string",
"description": "Gets the related Authorization Header from the destination by using the SAP Cloud SDK."
}
]
}
3 changes: 2 additions & 1 deletion docs/authentication/authentication-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Alert Notification service supports four types of authentication:
* _Basic_
* _OAuth_
* _mTLS_
* _mTLS, Basic, OAuth using the Destination Service_
* _mTLS, Basic, OAuth using the Destination Service indirectly_
* _Destination-Service Direct support within the name of the destination configured on the BTP Destination Service_
## Resources

* [Credential management](https://help.sap.com/viewer/5967a369d4b74f7a9c2b91f5df8e6ab6/Cloud/en-US/b90ed0f3a9604f8e844c73a78d5fad45.html)
58 changes: 58 additions & 0 deletions docs/authentication/destination-authentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
layout: default
title: Destination Authentication
parent: Authentication
nav_order: 1
permalink: /authentication/destinationService
---

# Basic Authentication
{: .no_toc }

## Table of contents
{: .no_toc .text-delta }

1. TOC
{:toc}

---

## Description

DestinationAuthentication is a class in the context of Alert Notification service node client. It helps you with acquiring the authorization header value, automatically by just providing the name of the destination.

It is using the SAP Cloud SDK to derive the `destinations` configured on a bound `destination-service-instance` or provided within the `default-env.json` for your local testing. For testing, you also could inject your destination configuration to the `process.env.destinations` variable.

Instead of the "mTLS Authentication using the Destination Service", you really do not have to store or obtain anything further. Just provide the name of the destination and the SAP Cloud SDK will do cover you :)

Find more details about the SAP Cloud SDK and the destination-handling [here](https://sap.github.io/cloud-sdk/docs/js/features/connectivity/destinations)

## Constructor properties

[comment]: <> For loop must remain on the lines, if changed table won't behave normally

| Field | Type | Description |
|:---:|:--:|:---------:| {% for field in site.data.destination-authentication.propertyFields %}
| {{field.name}} | {{ field.type }} | {{field.description}} | {% endfor %}

## Methods

[comment]: <> For loop must remain on the lines, if changed table won't behave normally

| Name | Returns | Description |
|:---:|:--:|:---------:| {% for method in site.data.destination-authentication.methods %}
| {{method.name}} | {{method.returnValue}}|{{method.description}} | {% endfor %}

## @Example

```js
import { DestinationAuthentication } from '@sap_oss/alert-notification-client';

const destAuthentication = new DestinationAuthentication({
destinationName: 'myWonderfulDestination'
});

destAuthentication.getAuthorizationHeaderValue()
.then(authHeaderValue => console.log(authHeaderValue))
.catch(error => console.log(error)); // The current call will print the authorization header value
```
Loading