Skip to content

feat: add public key client validation #1088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
93089e7
chore: add public key client validation
tiwarishubham635 May 12, 2025
b47617f
chore: run prettier
tiwarishubham635 May 12, 2025
d3a1ae5
chore: add signed headers
tiwarishubham635 May 12, 2025
c9f2659
Merge branch 'main' into node-pkcv
tiwarishubham635 May 12, 2025
dcc01dc
chore: fixed trailing new line characters
tiwarishubham635 May 15, 2025
e86b34d
Merge branch 'main' into node-pkcv
tiwarishubham635 May 16, 2025
220fdd8
chore: json.stringify requestbody before hashing
tiwarishubham635 May 16, 2025
55f9ba1
docs: add inline documentation
tiwarishubham635 May 16, 2025
9e4d6cc
chore: handle multiple content type of request body
tiwarishubham635 May 16, 2025
54c8067
chore: add namespace for validation token
tiwarishubham635 May 16, 2025
94ab31e
chore: export ValidationToken from twilio package
tiwarishubham635 May 16, 2025
6cab7e4
chore: added test cases
tiwarishubham635 May 19, 2025
e2ec2c5
chore: add localeCompare for ASCII sort
tiwarishubham635 May 19, 2025
b32ebea
chore: add custom compare for ASCII sort
tiwarishubham635 May 19, 2025
cc6dd44
chore: use specific datatype for queryParams and headerParams
tiwarishubham635 May 23, 2025
17f2f7d
chore: use template literals for concatenation
tiwarishubham635 May 23, 2025
c67ef1b
chore: add inline docs for validationClient and validation interceptor
tiwarishubham635 May 23, 2025
ac06376
chore: add exception handling for validation interceptor
tiwarishubham635 May 23, 2025
c27754e
docs: inline documentation for ValidationToken.ts
tiwarishubham635 May 23, 2025
b013de6
chore: add exception handling for validation token
tiwarishubham635 May 26, 2025
8406717
chore: add cluster test for pkcv
tiwarishubham635 May 26, 2025
fac1ec5
chore: run prettier
tiwarishubham635 May 26, 2025
830a337
chore: remove cluster test for pkcv
tiwarishubham635 May 26, 2025
225a5ea
chore: make ValidationToken attributes private
tiwarishubham635 May 26, 2025
82fb466
chore: run prettier
tiwarishubham635 May 26, 2025
0ca22a3
chore: block request on validation error
tiwarishubham635 May 27, 2025
5db3fef
chore: convert ASCIICompare to inline
tiwarishubham635 May 27, 2025
f8a5089
chore: run prettier
tiwarishubham635 May 27, 2025
83e4979
chore: add test for validation interceptor
tiwarishubham635 May 27, 2025
46991cc
chore: add test for ASCIICompare()
tiwarishubham635 May 28, 2025
356d987
Merge branch 'main' into node-pkcv
tiwarishubham635 May 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions examples/pkcv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var Twilio = require("../lib");
const crypto = require("crypto");

var accountSid = process.env.TWILIO_ACCOUNT_SID;
var token = process.env.TWILIO_AUTH_TOKEN;

// Uncomment the following line to specify a custom CA bundle for HTTPS requests:
// process.env.TWILIO_CA_BUNDLE = '/path/to/cert.pem';
// You can also set this as a regular environment variable outside of the code

// Generate public and private key pair
const { publicKey, privateKey } = crypto.generateKeyPairSync("rsa", {
modulusLength: 2048,
publicKeyEncoding: { type: "spki", format: "pem" },
privateKeyEncoding: { type: "pkcs8", format: "pem" },
});

// Create a default rest client
var client = new Twilio(accountSid, token);

// Submit the public key using the default client
client.accounts.v1.credentials.publicKey
.create({
friendlyName: "Public Key",
publicKey: publicKey,
})
.then((key) => {
// Create a new signing key using the default client
client.newSigningKeys.create().then((signingKey) => {
// Switch to the Validation Client to validate API calls
const validationClient = new Twilio(signingKey.sid, signingKey.secret, {
accountSid: accountSid,
validationClient: {
accountSid: accountSid,
credentialSid: key.sid,
signingKey: signingKey.sid,
privateKey: privateKey,
algorithm: "PS256", // Validation client supports RS256 or PS256 algorithm. Default is RS256.
},
});
validationClient.setAccountSid(accountSid);

validationClient.messages
.list({
from: process.env.TWILIO_PHONE_NUMBER,
limit: 10,
})
.then((messages) => {
console.log(messages);
})
.catch((err) => {
console.log("Error making API request: ", err);
});
});
})
.catch((err) => {
console.log("Error creating public key: ", err);
});
Loading
Loading