-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
1,163 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `network-auth` | ||
|
||
> TODO: description | ||
## Usage | ||
|
||
``` | ||
const networkAuth = require('network-auth'); | ||
// TODO: DEMONSTRATE API | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { | ||
NetworkClient, | ||
Purpose, | ||
Scope, | ||
} from '../../lib'; | ||
import { SDKTestCase, testPrivateKey } from '../../../../testHelpers'; | ||
import { AuthenticationType } from '@vonage/server-client'; | ||
|
||
class CIBAClient extends NetworkClient { | ||
protected authType?: AuthenticationType = AuthenticationType.CIBA | ||
|
||
protected _purpose = Purpose.FRAUD_PREVENTION_AND_DETECTION; | ||
protected _scope = Scope.NUMBER_VERIFICATION_VERIFY_READ; | ||
} | ||
|
||
export default [ | ||
{ | ||
label: 'can get CIBA request', | ||
baseUrl: 'https://api-eu.vonage.com', | ||
clientMethod: 'getCIBARequest', | ||
reqHeaders: { | ||
authorization: (value) => value.startsWith('Bearer '), | ||
}, | ||
client: new CIBAClient( | ||
{ | ||
privateKey: testPrivateKey, | ||
applicationId: 'my-application', | ||
msisdn: '447700900000', | ||
}, | ||
), | ||
requests: [ | ||
[ | ||
'/oauth2/bc-authorize', | ||
'POST', | ||
{ | ||
login_hint: `tel:+447700900000`, | ||
scope: `openid dpv:${Purpose.FRAUD_PREVENTION_AND_DETECTION}#${Scope.NUMBER_VERIFICATION_VERIFY_READ}`, | ||
}, | ||
], | ||
], | ||
responses: [ | ||
[ | ||
200, | ||
{ | ||
auth_req_id: 'auth-req-id', | ||
} | ||
], | ||
], | ||
generator: false, | ||
error: false, | ||
expected: 'auth-req-id' | ||
}, | ||
// { | ||
// label: 'error when requesting CIBA token returns 401', | ||
// baseUrl: 'https://api-eu.vonage.com', | ||
// clientMethod: 'getCIBAToken', | ||
// reqHeaders: { | ||
// authorization: (value) => value.startsWith('Bearer '), | ||
// }, | ||
// client: new CIBAClient( | ||
// { | ||
// privateKey: testPrivateKey, | ||
// applicationId: 'my-application', | ||
// msisdn: '447700900000', | ||
// }, | ||
// ), | ||
// requests: [ | ||
// [ | ||
// '/oauth2/bc-authorize', | ||
// 'POST', | ||
// { | ||
// login_hint: `tel:+447700900000`, | ||
// scope: `openid dpv:${Purpose.FRAUD_PREVENTION_AND_DETECTION}#${Scope.NUMBER_VERIFICATION_VERIFY_READ}`, | ||
// }, | ||
// ], | ||
// ], | ||
// responses: [ | ||
// [ | ||
// 401, | ||
// ], | ||
// ], | ||
// generator: false, | ||
// error: 'A 401 was returned when trying to get authorization. Some possible reasons for this:- The application id or private key are invalid. - You have not setup the Network API correctly for your application .', | ||
// expected: {foo: 'bar'} | ||
// }, | ||
// { | ||
// label: 'error when requesting CIBA token returns 400', | ||
// baseUrl: 'https://api-eu.vonage.com', | ||
// clientMethod: 'getCIBAToken', | ||
// reqHeaders: { | ||
// authorization: (value) => value.startsWith('Bearer '), | ||
// }, | ||
// client: new CIBAClient( | ||
// { | ||
// privateKey: testPrivateKey, | ||
// applicationId: 'my-application', | ||
// msisdn: '447700900000', | ||
// }, | ||
// ), | ||
// requests: [ | ||
// [ | ||
// '/oauth2/bc-authorize', | ||
// 'POST', | ||
// { | ||
// login_hint: `tel:+447700900000`, | ||
// scope: `openid dpv:${Purpose.FRAUD_PREVENTION_AND_DETECTION}#${Scope.NUMBER_VERIFICATION_VERIFY_READ}`, | ||
// }, | ||
// ], | ||
// ], | ||
// responses: [ | ||
// [ | ||
// 400, | ||
// ], | ||
// ], | ||
// generator: false, | ||
// error: 'It appears you have not enabled the Network API for your account. Please contact your account manager to enable this feature. ', | ||
// expected: {foo: 'bar'} | ||
// } | ||
] as SDKTestCase<CIBAClient>[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import getTests from './get'; | ||
|
||
export default [ | ||
{ | ||
name: 'GET tests', | ||
tests: getTests, | ||
}, | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import testDataSets from './__dataSets__'; | ||
import { VonageTest } from '../../../testHelpers'; | ||
|
||
VonageTest(testDataSets); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './purpose'; | ||
export * from './scope'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Netowrk API purposes for generating the scope | ||
*/ | ||
export enum Purpose { | ||
/** | ||
* Purpose for Fraud Prevention and Detection | ||
*/ | ||
FRAUD_PREVENTION_AND_DETECTION = 'FraudPreventionAndDetection', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Scopes for the API | ||
*/ | ||
export enum Scope { | ||
/** | ||
* Check for SIM Swap | ||
*/ | ||
CHECK_SIM_SWAP = 'check-sim-swap', | ||
|
||
/** | ||
* Number Verification | ||
*/ | ||
NUMBER_VERIFICATION_VERIFY_READ = 'number-verification-verify-read', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './invalidScopeError'; | ||
export * from './missingScopeError'; | ||
export * from './missingPurposeError'; | ||
export * from './invalidPurposeError'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Error thrown when purpose is invalid | ||
*/ | ||
export class InvalidPurposeError extends Error { | ||
constructor() { | ||
super(`You did not set a purpose for this request. Please set a proper purpose for this request.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Error thrown when scope is invalid | ||
*/ | ||
export class InvalidScopeError extends Error { | ||
constructor() { | ||
super(`You did not set a scope for this request. Please set a proper scope for this request.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Error thrown when purpose is invalid | ||
*/ | ||
export class MissingPurposeError extends Error { | ||
constructor() { | ||
super(`You did not set a purpose for this request.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Error thrown when no scope is set for a request. | ||
*/ | ||
export class MissingScopeError extends Error { | ||
constructor() { | ||
super(`You did not set a scope for this request.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './errors'; | ||
export * from './networkClient'; | ||
export * from './types'; | ||
export * from './enums'; |
Oops, something went wrong.