Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vonage/auth

Package Overview
Dependencies
Maintainers
42
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vonage/auth - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

dist/errors/index.d.ts

65

dist/auth.js

@@ -11,2 +11,3 @@ "use strict";

const enums_1 = require("./enums");
const index_1 = require("./errors/index");
const debug_1 = __importDefault(require("debug"));

@@ -27,6 +28,2 @@ const log = (0, debug_1.default)('vonage:auth');

this.jwtOptions = opts?.jwtOptions || {};
if (!opts?.privateKey) {
log('No private key set');
return;
}
if ((0, fs_1.existsSync)(opts.privateKey)) {

@@ -36,13 +33,40 @@ log('Reading private key file');

}
this.privateKey = opts.privateKey instanceof Buffer
? opts.privateKey.toString()
: opts.privateKey;
this.privateKey
= opts.privateKey instanceof Buffer
? opts.privateKey.toString()
: opts.privateKey;
}
getQueryParams = async (params) => ({
...params,
api_key: this.apiKey,
api_secret: this.apiSecret,
});
getQueryParams = async (params) => {
if (!this.apiKey) {
throw new index_1.MissingApiKeyError();
}
if (!this.apiSecret) {
throw new index_1.MissingApiSecretError();
}
if (typeof this.apiKey !== 'string') {
throw new index_1.InvalidApiKeyError();
}
if (typeof this.apiSecret !== 'string') {
throw new index_1.InvalidApiSecretError();
}
return {
...params,
api_key: this.apiKey,
api_secret: this.apiSecret,
};
};
createBasicHeader = async () => {
log('Creating basic auth header');
if (!this.apiKey) {
throw new index_1.MissingApiKeyError();
}
if (!this.apiSecret) {
throw new index_1.MissingApiSecretError();
}
if (typeof this.apiKey !== 'string') {
throw new index_1.InvalidApiKeyError();
}
if (typeof this.apiSecret !== 'string') {
throw new index_1.InvalidApiSecretError();
}
const buf = Buffer.from(`${this.apiKey}:${this.apiSecret}`);

@@ -57,2 +81,17 @@ return `Basic ${buf.toString('base64')}`;

log('Creating signature hash');
if (!this.apiKey) {
throw new index_1.MissingApiKeyError();
}
if (typeof this.apiKey !== 'string') {
throw new index_1.InvalidApiKeyError();
}
if (!this.signature.algorithm) {
throw new index_1.MissingSignatureError();
}
if (!this.signature.secret) {
throw new index_1.MissingApiSecretError();
}
if (typeof this.signature.secret !== 'string') {
throw new index_1.InvalidApiSecretError();
}
const returnParams = {

@@ -97,3 +136,3 @@ ...params,

default:
throw new Error(`Cannot sign request! Invalid algorithm: ${this.signature.algorithm}`);
throw new index_1.InvalidSignatureAlgorithmError();
}

@@ -100,0 +139,0 @@ return returnParams;

1

dist/index.d.ts
export * from './auth';
export * from './enums/index';
export * from './errors/index';
export * from './interfaces/index';
export * from './types/index';

@@ -19,4 +19,5 @@ "use strict";

__exportStar(require("./enums/index"), exports);
__exportStar(require("./errors/index"), exports);
__exportStar(require("./interfaces/index"), exports);
__exportStar(require("./types/index"), exports);
//# sourceMappingURL=index.js.map

@@ -0,2 +1,2 @@

export * from './AuthConstructor';
export * from './AuthInterface';
export * from './AuthConstructor';

@@ -17,4 +17,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./AuthConstructor"), exports);
__exportStar(require("./AuthInterface"), exports);
__exportStar(require("./AuthConstructor"), exports);
//# sourceMappingURL=index.js.map
{
"name": "@vonage/auth",
"version": "1.2.0",
"version": "1.3.0",
"description": "Vonage Auth Package adds the correct authentication headers to requests to Vonage API's",

@@ -26,3 +26,3 @@ "homepage": "https://github.com/vonage/vonage-node-sdk/tree/master/packages/auth#readme",

"dependencies": {
"@vonage/jwt": "^1.2.0",
"@vonage/jwt": "^1.3.0",
"debug": "^4.3.4"

@@ -29,0 +29,0 @@ },

# Vonage Auth SDK for Node.js
![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/vonage/vonage-node-sdk/Vonage/3.x?logo=github&style=flat-square&label=Workflow%20Build)
[![Codecov](https://img.shields.io/codecov/c/github/vonage/vonage-node-sdk?label=Codecov&logo=codecov&style=flat-square)](https://codecov.io/gh/Vonage/vonage-server-sdk)
![Latest Release](https://img.shields.io/github/v/release/vonage/vonage-node-sdk?logo=npm&style=flat-square)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-square)](../../CODE_OF_CONDUCT.md)
[![License](https://img.shields.io/npm/l/@vonage/auth?label=License&style=flat-square)][license]
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vonage/vonage-node-sdk/ci.yml?branch=3.x) [![Codecov](https://img.shields.io/codecov/c/github/vonage/vonage-node-sdk?label=Codecov&logo=codecov&style=flat-square)](https://codecov.io/gh/Vonage/vonage-server-sdk) ![Latest Release](https://img.shields.io/npm/v/@vonage/auth?label=%40vonage%2Fauth&style=flat-square) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-square)](../../CODE_OF_CONDUCT.md) [![License](https://img.shields.io/npm/l/@vonage/accounts?label=License&style=flat-square)][license]
<img src="https://developer.nexmo.com/images/logos/vbc-logo.svg" height="48px" alt="Vonage" />
This is the Vonage Auth SDK for Node.js for creating authentication headers and
signature for use with [Vonage APIs](https://www.vonage.com/). To use it you
will need a Vonage account. Sign up [for free at vonage.com][signup].
This is the Vonage Auth SDK for Node.js for creating authentication headers and signature for use with [Vonage APIs](https://www.vonage.com/). To use it you will need a Vonage account. Sign up [for free at vonage.com][signup].

@@ -20,3 +14,3 @@ We recommend using this package as part of the overall [`@vonage/server-sdk` package](https://github.com/vonage/vonage-node-sdk).

* [Installation](#installation)
* [Usage](#using-the-vonage-auth-sdk)
* [Usage](#usage)
* [Options](#options)

@@ -27,5 +21,3 @@ * [Testing](#testing)

We recommend using this SDK as part of the overall
[`@vonage/server-sdk` package](https://github.com/vonage/vonage-node-sdk).
Please see the main package for installation.
We recommend using this SDK as part of the overall [`@vonage/server-sdk` package](https://github.com/vonage/vonage-node-sdk). Please see the main package for installation.

@@ -46,12 +38,9 @@ You can also use this SDK standalone if you only need access to just the Auth SDK.

## Using the Vonage Auth SDK
## Usage
### As part of the Vonage Server SDK
If you are using this SDK as part of the Vonage Server SDK, you can access it as
the `auth` property off of the client that you instantiate.
If you are using this SDK as part of the Vonage Server SDK, you can access it as the `auth` property off of the client that you instantiate.
The SDK can be used standalone from the main [Vonage Server SDK for Node.js](https://github.com/vonage/vonage-node-sdk)
if you only need to use the Auth API. All you need to do is
`require('@vonage/auth')`, and use the returned object to create your own client.
The SDK can be used standalone from the main [Vonage Server SDK for Node.js](https://github.com/vonage/vonage-node-sdk) if you only need to use the Auth API. All you need to do is `require('@vonage/auth')`, and use the returned object to create your own client.

@@ -64,9 +53,12 @@ ```js

const vonageAuth = new Auth({
apiKey: API_KEY,
apiSecret: API_SECRET,
applicationId: APP_ID,
privateKey: PRIVATE_KEY_PATH,
apiKey: API_KEY,
apiSecret: API_SECRET,
applicationId: APP_ID,
privateKey: PRIVATE_KEY_PATH,
});
vonageAuth.createBasicHeader();
(async () => {
const basicHeader = vonageAuth.createBasicHeader();
console.log(basicHeader);
})()
```

@@ -78,10 +70,6 @@

* `apiKey` - API Key from Vonage API. If `applicationId` and `privateKey` are
present, `apiKey` is optional.
* `apiSecret` - API Secret from Vonage API. If `applicationId` and `privateKey`
are present, `apiSecret` is optional.
* `applicationId` - (optional) The Vonage API Application ID to be used when
creating JWTs.
* `privateKey` - (optional) The Private Key to be used when creating JWTs. You
can specify the key as any of the following:
* `apiKey` - API Key from Vonage API. If `applicationId` and `privateKey` are present, `apiKey` is optional.
* `apiSecret` - API Secret from Vonage API. If `applicationId` and `privateKey` are present, `apiSecret` is optional.
* `applicationId` - (optional) The Vonage API Application ID to be used when creating JWTs.
* `privateKey` - (optional) The Private Key to be used when creating JWTs. You can specify the key as any of the following:
* A [Buffer](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_string_encoding) containing the file contents.

@@ -88,0 +76,0 @@ * A String containing the path to the key file on disk.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc