Skip to content

Commit da3365d

Browse files
committed
Merge branch 'release-25.10' into 'main'
Release 25.10 TS content See merge request nwac/sdk-ts!139
2 parents fc0a40a + 1a7e962 commit da3365d

File tree

14 files changed

+163
-277
lines changed

14 files changed

+163
-277
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Version 6.0.0
4+
5+
Breaking Changes:
6+
- Number verification now uses the fast flow and requires the state parameter to be passed in
7+
38
## Version 5.2.0
49

510
Changes:

examples/number-verification.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,24 @@ const device = client.devices.get({
2020
You must provide a redirectUri, where the authorization code will be delivered.
2121
See the express example provided below.
2222
23-
You can add a state value of your choosing to test for CSRF attacks. Your application then should check,
23+
Add a state value of your choosing to test for CSRF attacks. Your application then should check,
2424
that the state value given to the authorization endpoint matches the one returned to the redirect uri.
2525
If the state values do not match, there has likely been a CSRF attack. In this case your application
2626
should return a 401 Unauthorized error code. */
2727

2828
const redirectUri = "https://my-example/redirect";
29-
const scope = "number-verification:verify";
29+
30+
// The scope should be "dpv:FraudPreventionAndDetection number-verification:device-phone-number:read"
31+
// when using the getPhoneNumber method to retrieve the device phone number.
32+
const scope = "dpv:FraudPreventionAndDetection number-verification:verify";
33+
3034
const loginHint = device.phoneNumber;
3135
const state = "foobar";
3236

33-
// create a callbacklink
34-
const callback = await client.authentication.createAuthenticationLink(
37+
38+
39+
// Create a callbacklink
40+
const callback = await client.authentication.createAuthorizationLink(
3541
redirectUri,
3642
scope,
3743
loginHint,
@@ -46,7 +52,7 @@ const port = process.env.PORT || 3000;
4652
app.use(express.json());
4753

4854
app.get("/redirect", (req: Request, res: Response) => {
49-
res.send(`This is your authorization code: ${req.query.code}`)
55+
res.send(`This is your authorization code: ${req.query.code} This is your state variable: ${req.query.state}.`)
5056

5157
res.status(200).end();
5258
});
@@ -56,20 +62,17 @@ app.listen(port, () => {
5662
});
5763

5864

59-
60-
6165
// Add your authorization code here.
6266
const code = "NaC-authorization-code";
6367

6468

6569
/* You can use the Number Verification API with the obtained authorization code.
6670
The verifyNumber endpoint will respond with a true or false value. */
67-
const verificationResult = await device.verifyNumber(code);
68-
71+
const verificationResult = await device.verifyNumber(code, state);
6972
console.log(verificationResult);
7073

71-
// The getPhoneNumber endpoint will respond with the phone number of the used Device.
7274

73-
const phoneNumber = await device.getPhoneNumber(code);
7475

76+
// The getPhoneNumber endpoint will respond with the phone number of the used Device.
77+
const phoneNumber = await device.getPhoneNumber(code, state);
7578
console.log(phoneNumber) // "+123456789"

integration-tests/geofencing.itest.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ describe("Geofencing", () => {
4343
const data: any = await notification.json();
4444

4545
expect(data).not.toBeNull();
46-
expect(data[0]["data"]["area"]["areaType"]).toEqual("CIRCLE");
47-
expect(data[0]["data"]["area"]["center"]["latitude"]).toEqual(47.48627616952785);
48-
expect(data[0]["data"]["area"]["radius"]).toEqual(2000);
46+
expect(data[0].data.area.areaType).toEqual("CIRCLE");
47+
expect(data[0].data.area.center.latitude).toEqual(47.48627616952785);
48+
expect(data[0].data.area.radius).toEqual(2000);
4949

5050

5151
// Deleting the subscription notification
@@ -79,8 +79,8 @@ describe("Geofencing", () => {
7979
const data: any = await notification.json();
8080

8181
expect(data).not.toBeNull();
82-
expect(data[0]["data"]["area"]["areaType"]).toEqual("POI");
83-
expect(data[0]["data"]["area"]["poiName"]).toEqual("StatueOfLiberty");
82+
expect(data[0].data.area.areaType).toEqual("POI");
83+
expect(data[0].data.area.poiName).toEqual("StatueOfLiberty");
8484

8585
// Deleting the subscription notification
8686
notification = await fetch(`${notificationUrl}/geofencing-subscriptions/${subscription.eventSubscriptionId}`,
@@ -112,7 +112,7 @@ describe("Geofencing", () => {
112112
const data: any = await notification.json();
113113

114114
expect(data).not.toBeNull();
115-
expect(data[0]["data"]["area"]["areaType"]).toEqual("CIRCLE");
115+
expect(data[0].data.area.areaType).toEqual("CIRCLE");
116116

117117

118118
// Deleting the subscription notification
@@ -146,7 +146,7 @@ describe("Geofencing", () => {
146146
const data: any = await notification.json();
147147

148148
expect(data).not.toBeNull();
149-
expect(data[0]["data"]["area"]["areaType"]).toEqual("POI");
149+
expect(data[0].data.area.areaType).toEqual("POI");
150150

151151
// Deleting the subscription notification
152152
notification = await fetch(`${notificationUrl}/geofencing-subscriptions/${subscription.eventSubscriptionId}`,
@@ -184,7 +184,7 @@ describe("Geofencing", () => {
184184
const data: any = await notification.json();
185185

186186
expect(data).not.toBeNull();
187-
expect(data[0]["data"]["area"]["areaType"]).toEqual("CIRCLE");
187+
expect(data[0].data.area.areaType).toEqual("CIRCLE");
188188

189189
// Deleting the subscription notification
190190
notification = await fetch(`${notificationUrl}/geofencing-subscriptions/${subscription.eventSubscriptionId}`,
@@ -225,7 +225,7 @@ describe("Geofencing", () => {
225225
const data: any = await notification.json();
226226

227227
expect(data).not.toBeNull();
228-
expect(data[0]["data"]["area"]["areaType"]).toEqual("POI");
228+
expect(data[0].data.area.areaType).toEqual("POI");
229229

230230
// Deleting the subscription notification
231231
notification = await fetch(`${notificationUrl}/geofencing-subscriptions/${subscription.eventSubscriptionId}`,
@@ -287,4 +287,4 @@ describe("Geofencing", () => {
287287
expect(error).toBeDefined();
288288
}
289289
});
290-
});
290+
});

integration-tests/numberVerification.itest.ts

Lines changed: 52 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,47 @@ beforeAll(() => {
2121
notificationUrl = configureNotificationServerUrl();
2222
});
2323

24-
describe("Number Verification authentication", () => {
24+
describe("Number Verification authorization", () => {
2525
it("should retrieve credentials", async () => {
26-
const credentials: any = await client.authentication.credentials();
26+
const credentials: any = await client.authorization.credentials();
2727
expect(credentials.clientId).toBeTruthy();
2828
expect(credentials.clientSecret).toBeTruthy();
2929
});
3030

3131
it("should retrieve endpoints", async () => {
32-
const endpoints: any = await client.authentication.endpoints();
33-
expect(endpoints.authorizationEndpoint).toBeTruthy();
34-
expect(endpoints.tokenEndpoint).toBeTruthy();
32+
const endpoints: any = await client.authorization.endpoints();
33+
expect(endpoints.fastFlowCspAuthEndpoint).toBeTruthy();
3534
});
3635

37-
it("should create authentication link", async () => {
38-
const credentials: any = await client.authentication.credentials();
39-
const endpoints: any = await client.authentication.endpoints();
36+
it("should create authorization link", async () => {
37+
const credentials: any = await client.authorization.credentials();
38+
const endpoints: any = await client.authorization.endpoints();
4039
const redirectUri= "https://example.com/redirect";
4140
const scope = "dpv:FraudPreventionAndDetection number-verification:verify";
4241
const loginHint = "+99999991000";
43-
const callback = await client.authentication.createAuthenticationLink(
42+
const state = "testState";
43+
const callback = await client.authorization.createAuthorizationLink(
4444
redirectUri,
4545
scope,
46-
loginHint
46+
loginHint,
47+
state
4748
);
4849
expect(callback)
49-
.toEqual(`${endpoints.authorizationEndpoint}?response_type=code&client_id=${credentials.clientId}&redirect_uri=https%3A%2F%2Fexample.com%2Fredirect&scope=dpv%3AFraudPreventionAndDetection%20number-verification%3Averify&login_hint=%2B99999991000`);
50+
.toEqual(`${endpoints.fastFlowCspAuthEndpoint}?response_type=code&client_id=${credentials.clientId}&redirect_uri=https%3A%2F%2Fexample.com%2Fredirect&scope=dpv%3AFraudPreventionAndDetection%20number-verification%3Averify&login_hint=%2B99999991000&state=testState`);
5051
});
5152
});
5253

53-
describe("Number Verification NaC auth code and access token", () => {
54-
it("should get NaC auth code", async () => {
54+
describe("Number Verification NaC auth code", () => {
55+
it("should get NaC auth code and state", async () => {
5556
const redirectUri= `${notificationUrl}/nv`;
5657
const scope = "dpv:FraudPreventionAndDetection number-verification:verify";
5758
const loginHint = "+99999991000";
58-
const callback = await client.authentication.createAuthenticationLink(
59+
const state = "testState";
60+
const callback = await client.authorization.createAuthorizationLink(
5961
redirectUri,
6062
scope,
61-
loginHint
63+
loginHint,
64+
state
6265
);
6366
await fetch(callback, {
6467
method: "GET",
@@ -71,123 +74,92 @@ describe("Number Verification NaC auth code and access token", () => {
7174
agent: agent
7275
});
7376
const data = await response.json() as any;
74-
const code = data.code
75-
expect(code).toBeTruthy();
76-
});
77-
78-
it("should get single use access token", async () => {
79-
const redirectUri= `${notificationUrl}/nv`;
80-
const scope = "dpv:FraudPreventionAndDetection number-verification:verify";
81-
const loginHint = "+99999991000";
82-
const callback = await client.authentication.createAuthenticationLink(
83-
redirectUri,
84-
scope,
85-
loginHint
86-
);
87-
await fetch(callback, {
88-
method: "GET",
89-
agent: agent
90-
});
91-
92-
const response = await fetch(`${notificationUrl}/nv-get-code`,
93-
{
94-
method: "GET",
95-
agent: agent
96-
});
97-
const data = await response.json() as any;
98-
const code = data.code
99-
const accessToken: any = await device.getSingleUseAccessToken(code);
100-
expect(accessToken.accessToken).toBeTruthy();
101-
expect(accessToken.tokenType).toBeTruthy();
102-
expect(accessToken.expiresIn).toBeTruthy();
77+
expect(data.code).toBeTruthy();
78+
expect(data.state).toBeTruthy();
10379
});
10480
});
10581

106-
describe("Number verification", () => {
82+
describe("Number verification", () => {
10783
it("should verify number - True", async () => {
10884
const redirectUri= `${notificationUrl}/nv`;
10985
const scope = "dpv:FraudPreventionAndDetection number-verification:verify";
11086
const loginHint = "+99999991000";
111-
const callback = await client.authentication.createAuthenticationLink(
87+
const state = "testState";
88+
const callback = await client.authorization.createAuthorizationLink(
11289
redirectUri,
11390
scope,
114-
loginHint
91+
loginHint,
92+
state
11593
);
11694
await fetch(callback, {
11795
method: "GET",
11896
agent: agent
11997
});
12098

12199
const response = await fetch(`${notificationUrl}/nv-get-code`,
122-
{
123-
method: "GET",
124-
agent: agent
125-
});
100+
{
101+
method: "GET",
102+
agent: agent
103+
});
126104
const data = await response.json() as any;
127-
const code = data.code
128-
const result: boolean = await device.verifyNumber(code);
105+
const result: boolean = await device.verifyNumber(data.code, data.state);
129106
expect(result).toBeTruthy();
130107
});
131108

132-
it.skip("should verify number - False", async () => {
109+
it("should verify number - False", async () => {
110+
device = client.devices.get({
111+
phoneNumber: "+99999991001"
112+
});
133113
const redirectUri= `${notificationUrl}/nv`;
134114
const scope = "dpv:FraudPreventionAndDetection number-verification:verify";
135115
const loginHint = "+99999991001";
136-
const callback = await client.authentication.createAuthenticationLink(
116+
const state = "testState";
117+
const callback = await client.authorization.createAuthorizationLink(
137118
redirectUri,
138119
scope,
139-
loginHint
120+
loginHint,
121+
state
140122
);
141123
await fetch(callback, {
142124
method: "GET",
143125
agent: agent
144126
});
145127

146128
const response = await fetch(`${notificationUrl}/nv-get-code`,
147-
{
148-
method: "GET",
149-
agent: agent
150-
});
129+
{
130+
method: "GET",
131+
agent: agent
132+
});
151133
const data = await response.json() as any;
152-
const code = data.code
153-
const result: boolean = await device.verifyNumber(code);
134+
const result: boolean = await device.verifyNumber(data.code, data.state);
154135
expect(result).toBeFalsy();
155136
});
156137

157-
it("should return 400 APIError", async () => {
158-
try {
159-
await device.getSingleUseAccessToken("1234567");
160-
expect(true).toBe(false);
161-
} catch (error){
162-
expect(error).toBeDefined();
163-
const err = error as Error;
164-
expect(err.message).toEqual("400 - Bad Request");
165-
}
166-
});
167138
});
168139
describe("Get Phone Number", () => {
169140
it("should get device phone number", async () => {
170141
const redirectUri= `${notificationUrl}/nv`;
171142
const scope = "dpv:FraudPreventionAndDetection number-verification:device-phone-number:read";
172143
const loginHint = "+99999991000";
173-
const callback = await client.authentication.createAuthenticationLink(
144+
const state = "testState"
145+
const callback = await client.authorization.createAuthorizationLink(
174146
redirectUri,
175147
scope,
176-
loginHint
148+
loginHint,
149+
state
177150
);
178151
await fetch(callback, {
179152
method: "GET",
180153
agent: agent
181154
});
182155

183156
const response = await fetch(`${notificationUrl}/nv-get-code`,
184-
{
185-
method: "GET",
186-
agent: agent
187-
});
157+
{
158+
method: "GET",
159+
agent: agent
160+
});
188161
const data = await response.json() as any;
189-
const code = data.code
190-
const result: string = await device.getPhoneNumber(code);
162+
const result: string = await device.getPhoneNumber(data.code, data.state);
191163
expect(result).toBeDefined();
192164
});
193165
});

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "network-as-code",
3-
"version": "5.2.0",
3+
"version": "6.0.0",
44
"description": "Network as Code SDK for TypeScript",
55
"main": "dist/esm/index.js",
66
"types": "dist/@types/index.d.ts",

0 commit comments

Comments
 (0)