OAuth Authentication

Table of contents

  1. Description
  2. Constructor properties
  3. Methods
  4. @Example

Description

OAuthAuthentication is a class in the context of Alert Notification service node client. It helps you with acquiring the authorization header value, when using OAuth Authentication mechanism, in order to authenticate yourself against Alert Notification service. For further information go to Credential Management and select OAuth2.0 Authentication with client ID and client secret (default) option.

Note: Grant type query parameter will be added automatically by the client with value client_credentials.

Note: In case you want the acquiring of the authorization header value to be realized with certificate and privateKey, client id query parameter will be added automatically by the client with value of the username field.

Constructor properties

Field Type Description
username string A tecnical client’s username
password string A technical client’s password
certificate string x509 certificate chain generated by UAA service
privateKey string Private key related to the generated certificate
oAuthTokenUrl string OAuth token URL to call on retrieving token

Methods

Name Returns Description
getAuthorizationHeaderValue() string Calls the oAuthTokenUrl and if username and password or username, certificate and privateKey are correct will retrieve an access token which will be cached for further use. If the access token is about to expire a new request to OAuth service will be made

@Example

import { OAuthAuthentication } from '@sap_oss/alert-notification-client';

const oAuthAuthentication = new OAuthAuthentication({
    username: 'test-username',
    password: 'test-password',
    oAuthTokenUrl: 'https://test.oauth.service.com/oauth/token'
});

oAuthAuthentication.getAuthorizationHeaderValue()
.then(authHeaderValue => console.log(authHeaderValue))
.catch(error => console.log(error)); // In the current case an error will be logged, as the provided arguments are invalid. In order for the call to pass you must provide valid arguments.
import { OAuthAuthentication } from '@sap_oss/alert-notification-client';

const oAuthAuthentication = new OAuthAuthentication({
    username: 'test-username',
    certificate: 'test-certificate',
    privateKey: 'test-privateKey',
    oAuthTokenUrl: 'https://test.oauth.cert.service.com/oauth/token'
});

oAuthAuthentication.getAuthorizationHeaderValue()
.then(authHeaderValue => console.log(authHeaderValue))
.catch(error => console.log(error)); // In the current case an error will be logged, as the provided arguments are invalid. In order for the call to pass you must provide valid arguments.