-
Notifications
You must be signed in to change notification settings - Fork 186
Vonage Network Auth
Documentation / Vonage Network Auth
This is the Vonage Server Client SDK for Node.js used to wrap the authentication headers/signatures for use with Vonage APIs. To use it you will need a Vonage account. Sign up for free at vonage.com.
For full API documentation refer to developer.vonage.com.
npm install @vonage/network-client
yarn add @vonage/network-client
To create a client, you will need to pass in a @vonage/auth
object.
const { Auth } = require('@vonage/auth');
const { Client } = require('@vonage/network-client');
const vonageClient = new Client (new Auth({
apiKey: API_KEY,
apiSecret: API_SECRET,
applicationId: APP_ID,
privateKey: PRIVATE_KEY_PATH,
}),
options,
);
options
is any option from @vonage/server-client
along with the following that are specific for the network APIs
-
msisdn: string
- The MSISDN (phone number) you wish to authenticate to. -
accessToken: string
(optional) - A pre generated Access token for making network API calls -
expiresIn: string
(required ifaccessToken
is passed) - Time until the access token expires
Run:
npm run test
Defined in: packages/network-client/lib/enums/purpose.ts:4
Netowrk API purposes for generating the scope
Enumeration Member | Value | Description | Defined in |
---|---|---|---|
FRAUD_PREVENTION_AND_DETECTION
|
"FraudPreventionAndDetection" |
Purpose for Fraud Prevention and Detection | packages/network-client/lib/enums/purpose.ts:8 |
Defined in: packages/network-client/lib/enums/scope.ts:4
Scopes for the API
Enumeration Member | Value | Description | Defined in |
---|---|---|---|
CHECK_SIM_SWAP
|
"check-sim-swap" |
Check for SIM Swap | packages/network-client/lib/enums/scope.ts:8 |
NUMBER_VERIFICATION_VERIFY_READ
|
"number-verification-verify-read" |
Number Verification | packages/network-client/lib/enums/scope.ts:13 |
Defined in: packages/network-client/lib/errors/invalidPurposeError.ts:5
Error thrown when purpose is invalid
Error
new InvalidPurposeError(): InvalidPurposeError;
Defined in: packages/network-client/lib/errors/invalidPurposeError.ts:6
Error.constructor
optional cause: unknown;
Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:24
Error.cause
message: string;
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1077
Error.message
name: string;
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076
Error.name
optional stack: string;
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078
Error.stack
static stackTraceLimit: number;
Defined in: node_modules/@types/node/globals.d.ts:161
The Error.stackTraceLimit
property specifies the number of stack frames
collected by a stack trace (whether generated by new Error().stack
or
Error.captureStackTrace(obj)
).
The default value is 10
but may be set to any valid JavaScript number. Changes
will affect any stack trace captured after the value has been changed.
If set to a non-number value, or set to a negative number, stack traces will not capture any frames.
Error.stackTraceLimit
static captureStackTrace(targetObject, constructorOpt?): void;
Defined in: node_modules/@types/node/globals.d.ts:145
Creates a .stack
property on targetObject
, which when accessed returns
a string representing the location in the code at which
Error.captureStackTrace()
was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`
The first line of the trace will be prefixed with
${myObject.name}: ${myObject.message}
.
The optional constructorOpt
argument accepts a function. If given, all frames
above constructorOpt
, including constructorOpt
, will be omitted from the
generated stack trace.
The constructorOpt
argument is useful for hiding implementation
details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();
object
Function
void
Error.captureStackTrace
static prepareStackTrace(err, stackTraces): any;
Defined in: node_modules/@types/node/globals.d.ts:149
Error
CallSite
[]
any
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Error.prepareStackTrace
Defined in: packages/network-client/lib/errors/invalidScopeError.ts:5
Error thrown when scope is invalid
Error
new InvalidScopeError(): InvalidScopeError;
Defined in: packages/network-client/lib/errors/invalidScopeError.ts:6
Error.constructor
optional cause: unknown;
Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:24
Error.cause
message: string;
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1077
Error.message
name: string;
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076
Error.name
optional stack: string;
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078
Error.stack
static stackTraceLimit: number;
Defined in: node_modules/@types/node/globals.d.ts:161
The Error.stackTraceLimit
property specifies the number of stack frames
collected by a stack trace (whether generated by new Error().stack
or
Error.captureStackTrace(obj)
).
The default value is 10
but may be set to any valid JavaScript number. Changes
will affect any stack trace captured after the value has been changed.
If set to a non-number value, or set to a negative number, stack traces will not capture any frames.
Error.stackTraceLimit
static captureStackTrace(targetObject, constructorOpt?): void;
Defined in: node_modules/@types/node/globals.d.ts:145
Creates a .stack
property on targetObject
, which when accessed returns
a string representing the location in the code at which
Error.captureStackTrace()
was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`
The first line of the trace will be prefixed with
${myObject.name}: ${myObject.message}
.
The optional constructorOpt
argument accepts a function. If given, all frames
above constructorOpt
, including constructorOpt
, will be omitted from the
generated stack trace.
The constructorOpt
argument is useful for hiding implementation
details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();
object
Function
void
Error.captureStackTrace
static prepareStackTrace(err, stackTraces): any;
Defined in: node_modules/@types/node/globals.d.ts:149
Error
CallSite
[]
any
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Error.prepareStackTrace
Defined in: packages/network-client/lib/errors/missingPurposeError.ts:5
Error thrown when purpose is invalid
Error
new MissingPurposeError(): MissingPurposeError;
Defined in: packages/network-client/lib/errors/missingPurposeError.ts:6
Error.constructor
optional cause: unknown;
Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:24
Error.cause
message: string;
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1077
Error.message
name: string;
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076
Error.name
optional stack: string;
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078
Error.stack
static stackTraceLimit: number;
Defined in: node_modules/@types/node/globals.d.ts:161
The Error.stackTraceLimit
property specifies the number of stack frames
collected by a stack trace (whether generated by new Error().stack
or
Error.captureStackTrace(obj)
).
The default value is 10
but may be set to any valid JavaScript number. Changes
will affect any stack trace captured after the value has been changed.
If set to a non-number value, or set to a negative number, stack traces will not capture any frames.
Error.stackTraceLimit
static captureStackTrace(targetObject, constructorOpt?): void;
Defined in: node_modules/@types/node/globals.d.ts:145
Creates a .stack
property on targetObject
, which when accessed returns
a string representing the location in the code at which
Error.captureStackTrace()
was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`
The first line of the trace will be prefixed with
${myObject.name}: ${myObject.message}
.
The optional constructorOpt
argument accepts a function. If given, all frames
above constructorOpt
, including constructorOpt
, will be omitted from the
generated stack trace.
The constructorOpt
argument is useful for hiding implementation
details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();
object
Function
void
Error.captureStackTrace
static prepareStackTrace(err, stackTraces): any;
Defined in: node_modules/@types/node/globals.d.ts:149
Error
CallSite
[]
any
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Error.prepareStackTrace
Defined in: packages/network-client/lib/errors/missingScopeError.ts:5
Error thrown when no scope is set for a request.
Error
new MissingScopeError(): MissingScopeError;
Defined in: packages/network-client/lib/errors/missingScopeError.ts:6
Error.constructor
optional cause: unknown;
Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:24
Error.cause
message: string;
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1077
Error.message
name: string;
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076
Error.name
optional stack: string;
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078
Error.stack
static stackTraceLimit: number;
Defined in: node_modules/@types/node/globals.d.ts:161
The Error.stackTraceLimit
property specifies the number of stack frames
collected by a stack trace (whether generated by new Error().stack
or
Error.captureStackTrace(obj)
).
The default value is 10
but may be set to any valid JavaScript number. Changes
will affect any stack trace captured after the value has been changed.
If set to a non-number value, or set to a negative number, stack traces will not capture any frames.
Error.stackTraceLimit
static captureStackTrace(targetObject, constructorOpt?): void;
Defined in: node_modules/@types/node/globals.d.ts:145
Creates a .stack
property on targetObject
, which when accessed returns
a string representing the location in the code at which
Error.captureStackTrace()
was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`
The first line of the trace will be prefixed with
${myObject.name}: ${myObject.message}
.
The optional constructorOpt
argument accepts a function. If given, all frames
above constructorOpt
, including constructorOpt
, will be omitted from the
generated stack trace.
The constructorOpt
argument is useful for hiding implementation
details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();
object
Function
void
Error.captureStackTrace
static prepareStackTrace(err, stackTraces): any;
Defined in: node_modules/@types/node/globals.d.ts:149
Error
CallSite
[]
any
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Error.prepareStackTrace
Defined in: packages/network-client/lib/networkClient.ts:26
new NetworkClient(auth, config?): NetworkClient;
Defined in: packages/network-client/lib/networkClient.ts:62
protected _msisdn: string;
Defined in: packages/network-client/lib/networkClient.ts:45
The msisdn that will be used for API calls
protected optional _purpose: FRAUD_PREVENTION_AND_DETECTION;
Defined in: packages/network-client/lib/networkClient.ts:50
The purpose for the scope
protected optional _scope: Scope;
Defined in: packages/network-client/lib/networkClient.ts:55
The scope for the token
protected optional accessToken: string;
Defined in: packages/network-client/lib/networkClient.ts:35
The current token
protected auth: AuthInterface;
Defined in: packages/server-client/dist/lib/client.d.ts:24
The authentication instance responsible for generating authentication headers and query parameters.
protected optional authType: AuthenticationType;
Defined in: packages/server-client/dist/lib/client.d.ts:20
The type of authentication used for the client's requests.
protected config: NetworkConfigParameters;
Defined in: packages/network-client/lib/networkClient.ts:60
Configuration settings for the client, including default hosts for various services and other request settings.
protected expires: number = 0;
Defined in: packages/network-client/lib/networkClient.ts:40
Timestamp until the token expires
protected gettingToken: boolean = false;
Defined in: packages/network-client/lib/networkClient.ts:30
Flags if we are currently getting a token
static transformers: object;
Defined in: packages/server-client/dist/lib/client.d.ts:11
Static property containing utility transformers.
camelCaseObjectKeys: PartialTransformFunction;
kebabCaseObjectKeys: PartialTransformFunction;
omit: (keys, obj) => TransformedObject;
string
[]
snakeCaseObjectKeys: PartialTransformFunction;
get msisdn(): string;
Defined in: packages/network-client/lib/networkClient.ts:81
Get the msisdn
If the msisdn is not set
string
The msisdn
get purpose(): FRAUD_PREVENTION_AND_DETECTION;
Defined in: packages/network-client/lib/networkClient.ts:96
Get the purpose
If the purpose is not set
If the purpose is not valid
FRAUD_PREVENTION_AND_DETECTION
The purpose
set purpose(value): void;
Defined in: packages/network-client/lib/networkClient.ts:112
Set the purpose
FRAUD_PREVENTION_AND_DETECTION
The purpose
void
get scope(): Scope;
Defined in: packages/network-client/lib/networkClient.ts:123
Get the scope
If the scope is not set
If the scope is not valid
The scope
set scope(value): void;
Defined in: packages/network-client/lib/networkClient.ts:142
Set the scope
If the scope is not valid
If the scope is not set
The scope
void
addAuthenticationToRequest(request): Promise<VetchOptions>;
Defined in: packages/network-client/lib/networkClient.ts:154
Add authentication to the auth
This will make the calls to get a network token if required.
The request to add authentication to
Promise
<VetchOptions
>
The request with authentication added
Client
.addAuthenticationToRequest
protected addBasicAuthToRequest(request): Promise<VetchOptions>;
Defined in: packages/server-client/dist/lib/client.d.ts:71
Adds basic authentication headers to the request.
The request options to which authentication needs to be added.
Promise
<VetchOptions
>
- The request options with the added authentication.
protected addJWTToRequest(request): Promise<VetchOptions>;
Defined in: packages/server-client/dist/lib/client.d.ts:64
Adds a JWT to the request.
The request options to which authentication needs to be added.
Promise
<VetchOptions
>
- The request options with the added authentication.
protected addQueryKeySecretToRequest(request): Promise<VetchOptions>;
Defined in: packages/server-client/dist/lib/client.d.ts:57
Adds API key and secret to the request.
The request options to which authentication needs to be added.
Promise
<VetchOptions
>
- The request options with the added authentication.
Client
.addQueryKeySecretToRequest
protected addQueryKeySecretToRequestBody(request): Promise<VetchOptions>;
Defined in: packages/server-client/dist/lib/client.d.ts:50
Adds API key and secret to the request body.
The request options to which authentication needs to be added.
Promise
<VetchOptions
>
- The request options with the added authentication.
Client
.addQueryKeySecretToRequestBody
buildOIDCURL(state): string;
Defined in: packages/network-client/lib/networkClient.ts:191
Build the URL for the OIDC flow
string
= ''
The state to use
string
The URL for the OIDC flow
exchangeCodeForToken(code): Promise<NetworkTokenResponse>;
Defined in: packages/network-client/lib/networkClient.ts:224
Exchange the code for a network token
string
The code to exchange
Promise
<NetworkTokenResponse
>
The network token token
protected getCIBAAccessToken(cibaRequestId): Promise<NetworkTokenResponse>;
Defined in: packages/network-client/lib/networkClient.ts:306
Get a network token
string
The CIBA request id
Promise
<NetworkTokenResponse
>
The network token data
protected getCIBARequestId(): Promise<string>;
Defined in: packages/network-client/lib/networkClient.ts:355
Get an CIBA request id
Promise
<string
>
The CIBA request id
protected getCIBAToken(): Promise<void>;
Defined in: packages/network-client/lib/networkClient.ts:283
Get the access token for the CIBA flow
This is a two step process. First we need to get an CIBA request id, then we can use that to get a network token.
Promise
<void
>
getConfig(): ConfigParams;
Defined in: packages/server-client/dist/lib/client.d.ts:36
protected parseResponse<T>(request, response): Promise<VetchResponse<T>>;
Defined in: packages/server-client/dist/lib/client.d.ts:168
Parses the response based on its content type.
T
The expected type of the parsed response data.
The request options.
Response
The raw response from the request.
Promise
<VetchResponse
<T
>>
- The parsed response.
protected prepareBody(request): undefined | string;
Defined in: packages/server-client/dist/lib/client.d.ts:158
Prepares the body for the request based on the content type.
The request options.
undefined
| string
- The prepared request body as a string or undefined.
protected prepareRequest(request): Promise<VetchOptions>;
Defined in: packages/server-client/dist/lib/client.d.ts:151
Prepares the request with necessary headers, authentication, and query parameters.
The initial request options.
Promise
<VetchOptions
>
- The modified request options.
sendDeleteRequest<T>(url): Promise<VetchResponse<T>>;
Defined in: packages/server-client/dist/lib/client.d.ts:78
Sends a DELETE request to the specified URL.
T
string
The URL endpoint for the DELETE request.
Promise
<VetchResponse
<T
>>
- The response from the DELETE request.
sendFormSubmitRequest<T>(url, payload?): Promise<VetchResponse<T>>;
Defined in: packages/server-client/dist/lib/client.d.ts:86
Sends a POST request with form data to the specified URL.
T
string
The URL endpoint for the POST request.
Record
<string
, undefined
| string
>
Optional payload containing form data to send with the POST request.
Promise
<VetchResponse
<T
>>
- The response from the POST request.
sendGetRequest<T>(url, queryParams?): Promise<VetchResponse<T>>;
Defined in: packages/server-client/dist/lib/client.d.ts:94
Sends a GET request to the specified URL with optional query parameters.
T
string
The URL endpoint for the GET request.
Optional query parameters to append to the URL. These should be compatible with Node's URLSearchParams.
Promise
<VetchResponse
<T
>>
- The response from the GET request.
sendPatchRequest<T>(url, payload?): Promise<VetchResponse<T>>;
Defined in: packages/server-client/dist/lib/client.d.ts:104
Sends a PATCH request to the specified URL with an optional payload.
T
string
The URL endpoint for the PATCH request.
Optional payload to be sent as the body of the PATCH request.
Promise
<VetchResponse
<T
>>
- The response from the PATCH request.
sendPostRequest<T>(url, payload?): Promise<VetchResponse<T>>;
Defined in: packages/server-client/dist/lib/client.d.ts:114
Sends a POST request to the specified URL with an optional payload.
T
string
The URL endpoint for the POST request.
Optional payload to be sent as the body of the POST request.
Promise
<VetchResponse
<T
>>
- The response from the POST request.
sendPutRequest<T>(url, payload?): Promise<VetchResponse<T>>;
Defined in: packages/server-client/dist/lib/client.d.ts:124
Sends a PUT request to the specified URL with an optional payload.
T
string
The URL endpoint for the PUT request.
Optional payload to be sent as the body of the PUT request.
Promise
<VetchResponse
<T
>>
- The response from the PUT request.
sendRequest<T>(request): Promise<VetchResponse<T>>;
Defined in: packages/server-client/dist/lib/client.d.ts:144
Sends a request adding necessary headers, handling authentication, and parsing the response.
T
The options defining the request, including URL, method, headers, and data.
Promise
<VetchResponse
<T
>>
- The parsed response from the request.
sendRequestWithData<T>(
method,
url,
payload?): Promise<VetchResponse<T>>;
Defined in: packages/server-client/dist/lib/client.d.ts:135
Sends a request with JSON-encoded data to the specified URL using the provided HTTP method.
T
The HTTP method to be used for the request (only POST, PATCH, or PUT are acceptable).
string
The URL endpoint for the request.
Optional payload to be sent as the body of the request, JSON-encoded.
Promise
<VetchResponse
<T
>>
- The response from the request.
type CIBAResponse = object;
Defined in: packages/network-client/lib/types/responses/odicResponse.ts:1
auth_req_id: string;
Defined in: packages/network-client/lib/types/responses/odicResponse.ts:5
CIBA ODIC token
expires_in: number;
Defined in: packages/network-client/lib/types/responses/odicResponse.ts:10
Seconds until the token expires
optional interval: string;
Defined in: packages/network-client/lib/types/responses/odicResponse.ts:15
This is the minimum polling interval in seconds
type NetworkAuthParameters = AuthParams & object;
Defined in: packages/network-client/lib/types/parameters/networkAuthParameters.ts:3
optional accessToken: string;
The access token to use for API calls
optional expiresIn: number;
The expiration time of the access token (in seconds)
msisdn: string;
The msisdn that will be used for API calls
type NetworkConfigParameters = ConfigParams & object;
Defined in: packages/network-client/lib/types/parameters/networkConfigParameters.ts:3
optional networkApiHost: string;
URL for making calls to get a network token
optional odicHost: string;
URL for making calls to get a network token
optional redirectUri: string;
The URL to redirect to for the OAuth flow
type NetworkTokenResponse = object;
Defined in: packages/network-client/lib/types/responses/networkTokenResponse.ts:1
access_token: string;
Defined in: packages/network-client/lib/types/responses/networkTokenResponse.ts:5
The token
expires_in: number;
Defined in: packages/network-client/lib/types/responses/networkTokenResponse.ts:15
The time in seconds from now that the token expires
token_type: "Bearer";
Defined in: packages/network-client/lib/types/responses/networkTokenResponse.ts:10
The type of token