npm package: @splunkdev/cloud-auth-node
Description: Splunk Cloud Node Authentication Library for Node.js applications
Author: Splunk, Inc.
Latest version: 2.1.0

# Splunk Cloud Services Cloud-Auth-Node

[![Build Status](https://github.com/splunk/splunk-cloud-auth-js/workflows/Build%20and%20Run%20Tests/badge.svg?branch=master)](https://github.com/splunk/splunk-cloud-auth-js/actions?query=workflow%3A%22Build+and+Run+Tests%22+branch%3Amaster)
[![codecov](https://codecov.io/gh/splunk/splunk-cloud-auth-js/branch/master/graphs/badge.svg)](https://codecov.io/gh/splunk/splunk-cloud-auth-js)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

Splunk Cloud Services Cloud-Auth-Node contains an authentication library for Node.js applications, along with code and examples to enable you to authenticate with Splunk Cloud Services in a Node.js-based application using the JavaScript programming language.

You can use the `@splunkdev/cloud-auth-node` library alone or with the [Splunk Cloud Services SDK for JavaScript](https://github.com/splunk/splunk-cloud-sdk-js/) to programatically access Splunk Cloud Services.

## Terms of Service

[Splunk Cloud Services Terms of Service](https://auth.scp.splunk.com/tos)

## Authorization Grant Types

This library supports the following OAuth authorization grant types:

-   [Client Credentials](https://oauth.net/2/grant-types/client-credentials/)
-   [Proof Key for Code Exchange](https://oauth.net/2/pkce/) (PKCE)
-   [Refresh Token](https://oauth.net/2/grant-types/refresh-token/)

For more about authorization flows that are supported by Splunk Cloud Services, see [Plan apps for Splunk Cloud Services](https://dev.splunk.com/scs/docs/apps/plan#Choose-an-authorization-flow) on the Splunk Developer Portal.

## Get started

Install the `@splunkdev/cloud-auth-node` package to enable your project to authenticate with Splunk Cloud Services.

Run the following command from your project directory if you use Yarn:

```sh-session
yarn add @splunkdev/cloud-auth-node
```

Run the following command from your project directory if you use npm:

```sh-session
npm install --save @splunkdev/cloud-auth-node
```

### Example

This example demonstrates how to use this library and the Client Credential authorization flow with the Splunk Cloud Services SDK for JavaScript.

```js
require('isomorphic-fetch'); // Or a fetch polyfill of your choosing

const { SplunkCloud } = require('@splunkdev/cloud-sdk');
const { ClientAuthManager, ClientAuthManagerSettings } = require('@splunkdev/cloud-auth-node');

// Initialize AuthManagerSettings
const authSettings = new ClientAuthManagerSettings(
    host = SPLUNK_CLOUD_AUTH_HOST,
    scope = '',
    clientId = CLIENT_CREDENTIAL_ID,
    clientSecret = CLIENT_CREDENTIAL_SECRET,
    grantType = 'client_credentials',
    tenant = TENANT);

// Use AuthManagerSettings to initialize an AuthManager.
const authManager = new ClientAuthManager(authSettings);

// Use AuthManager as the tokenSource to initialize SplunkCloud.
const svc = new SplunkCloud({ tokenSource: authManager, defaultTenant: TENANT });

...

```

For additional examples, see the [examples directory](examples).

## Documentation

For Splunk Cloud Services documentation, see the [Splunk Developer Portal](https://dev.splunk.com/scs/).

## Contact

If you have questions, reach out to us on [Slack](https://splunkdevplatform.slack.com) in the **#sdc** channel or email us at _devinfo@splunk.com_.