• Stars
    star
    127
  • Rank 282,790 (Top 6 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created almost 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A sample backend that demonstrates how to generate a Virgil JWT and Twilio token used for authentication with the Virgil and Twilio services

Twilio Sample Backend for Node.js

This repository contains a sample backend code that demonstrates how to combine Virgil and Twilio JWT generation, which are used for authentication with the Virgil and Twilio services.

Do not use this authentication in production. Requests to a /virgil-jwt and /twilio-jwt endpoints must be allowed for authenticated users. Use your application authorization strategy.

Prerequisites

Set up and run demo

Clone

Clone the repository from GitHub.

$ git clone https://github.com/VirgilSecurity/twilio-sample-backend-nodejs.git

Get Virgil Credentials

If you don't have an account yet, sign up for one using your e-mail.

You can download a ready-to-use .env file

  1. Navigate to the Virgil Dashboard -> Your Application -> E3Kit Section.
  2. Generate .env in the .env file section.
  3. Download the generated file, paste it into the project root folder and rename it to .env.

Or you can add the parameters manually:

To generate a Virgil JWT the following values are required:

Variable Name Description
APP_ID ID of your Virgil Application.
APP_KEY Private key of your App that is used to sign the JWTs.
APP_KEY_ID ID of your App Key. A unique string value that identifies your account in the Virgil Cloud.
  1. Copy and rename .env.example to .env.
  2. Create Application in the Virgil Dashboard, copy its APP_ID to the .env file;
  3. Create App Key and save its private key value to APP_KEY line in the .env file;
  4. Copy ID of the created key to APP_KEY_ID line in the .env file;

Get Twilio Credentials

To generate a Twilio JWT the following values are required:

Variable Name Description
TWILIO_ACCOUNT_SID Your primary Twilio account identifier - find this in the console here.
TWILIO_API_KEY_SID SID of Twilio Api Key. Used for authentication on Twilio services. Generated with TWILIO_API_SECRET
TWILIO_API_SECRET Twilio API key secret: generate one here
TWILIO_SERVICE_SID A service instance where all the data for our application is stored and scoped. Generate one in the console here.

Add this parameters to your .env file.

Install Dependencies and Run the Server

$ npm install
$ npm run start

Now, use your client code to make a request to get a JWT from the sample backend that is working on http://localhost:3000.

Along with the backend we provide a demonstration of a simple client chat interacting with Virgil API, which you can see if you navigate to http://localhost:3000 at your browser. The sample chat code is located in the the public directory.

Demo screenshot

Specification

/authenticate endpoint

This endpoint is an example of users authentication. It takes user identity and responds with unique token.

POST https://localhost:3000/authenticate HTTP/1.1
Content-type: application/json;

{
    "identity": "string"
}

Response:

{
    "authToken": "string"
}

/virgil-jwt endpoint

This endpoint checks whether a request is authenticated by an authorization header. It takes user's authToken, finds related user identity and generates a virgilToken (which is JSON Web Token) with this identity in a payload. Use this token to make authorized API calls to Virgil Cloud.

GET https://localhost:3000/virgil-jwt HTTP/1.1
Content-type: application/json;
Authorization: Bearer <authToken>

Response:

{
    "virgilToken": "string"
}

/twilio-jwt endpoint

Same as Virgil token endpoint Twilio endpoint should be protected and responds with twilioToken.

GET https://localhost:3000/twilio-jwt HTTP/1.1
Content-type: application/json;
Authorization: Bearer <authToken>

Response:

{
    "twilioToken": "string"
}

Virgil JWT Generation

To generate a Virgil JWT, you need to use the JwtGenerator class from the Virgil SDK.

const virgilCrypto = new VirgilCrypto();

const generator = new JwtGenerator({
  appId: process.env.APP_ID,
  apiKeyId: process.env.API_KEY_ID,
  apiKey: virgilCrypto.importPrivateKey(process.env.API_PRIVATE_KEY),
  accessTokenSigner: new VirgilAccessTokenSigner(virgilCrypto)
});

Then you need to provide an HTTP endpoint which will return the JWT with the user's identity as a JSON.

For more details take a look at the virgilToken.js file.

License

This library is released under the 3-clause BSD License.

Support

Our developer support team is here to help you. Find out more information on our Help Center.

You can find us on Twitter or send us email [email protected].

Also, get extra help from our support team on Slack.

More Repositories

1

awesome-virgil

Key Management and Crypto Building Block for your App or Device.
162
star
2

virgil-cli

CLI tool to manage your Virgil account and applications.
Go
83
star
3

virgil-crypto

Virgil Crypto is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant. Crypto Library is written in C++, suitable for mobile and server platforms and supports bindings with: Swift, Obj-C, Java (Android), С#/.NET, JS, Python, Ruby, PHP, Go.
C++
83
star
4

virgil-e3kit-js

E3Kit is a security framework that simplifies work with Virgil services and presents the easiest way to add full end-to-end security to your chat application to become HIPAA and GDPR compliant and more.
TypeScript
58
star
5

demo-sharing-js

This is a demo app shows how you can create a secure file sharing app using Virgil Crypto Library in Javascript.
JavaScript
53
star
6

react-native-virgil-crypto

JavaScript
48
star
7

demo-firebase-ios

[DEPRECATED] See https://github.com/VirgilSecurity/demo-e3kit-ios and https://github.com/VirgilSecurity/virgil-e3kit-firebase-func for up-to-date code. -- A simple iOS application that demonstrates how the end-to-end encryption works. The application uses firebase as a backend service for authentication and chat messaging.
Swift
40
star
8

demo-firebase-android

[DEPRECATED] See https://github.com/VirgilSecurity/demo-e3kit-android and https://github.com/VirgilSecurity/virgil-e3kit-firebase-func for up-to-date code. A simple Android application that demonstrates how the end-to-end encryption works. The application uses firebase as a backend service for authentication and chat messaging.
Java
38
star
9

virgil-crypto-javascript

Virgil JavaScript Crypto Library is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant.
TypeScript
35
star
10

virgil-crypto-x

Virgil Crypto stack Objective-C/Swift
Swift
34
star
11

virgil-crypto-c

This library is designed to be small, flexible and convenient wrapper for a variety crypto algorithms. So it can be used in a small micro controller as well as in a high load server application.
C
34
star
12

demo-firebase-js

A simple Web application that demonstrates how the end-to-end encryption works. The application uses firebase as a backend service for authentication and chat messaging, and Virgil E3Kit SDK for end-to-end encryption.
TypeScript
33
star
13

virgil-sdk-javascript

Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.
TypeScript
32
star
14

virgil-crypto-php

Virgil PHP Crypto Library is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant.
PHP
32
star
15

virgil-sdk-x

Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.
Swift
27
star
16

virgil-nginx-noise-socket

Nginx module that implements Noise Socket Protocol by using Virgil Security infrastructure.
C
26
star
17

chat-back4app-android

(Works!) A simple Back4App Android application based on Virgil E3Kit that demonstrates how the end-to-end encryption works.
Kotlin
25
star
18

virgil-sdk-java-android

Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.
Java
25
star
19

virgil-iotkit

Virgil IoTKit is a C library for connecting IoT devices to Virgil IoT Security PaaS. IoTKit helps you easily add security to your IoT devices at any lifecycle stage for secure provisioning and authenticating devices, secure updating firmware and trust chain, and for secure exchanging messages using any transport protocols.
C
22
star
20

virgil-e3kit-firebase-func

Backend's function that connects your Virgil and Firebase accounts for implementing end-to-end encryption
JavaScript
21
star
21

virgil-sdk-cpp

Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.
C++
18
star
22

virgil-sdk-net

Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.
C#
16
star
23

virgil-phe-go

Password-Hardened Encryption protocol implemented in Go.
Go
15
star
24

virgil-e3kit-x

E3Kit is a security framework that simplifies work with Virgil services and presents the easiest way to add full end-to-end security to your chat application to become HIPAA and GDPR compliant and more.
Swift
14
star
25

demo-e3kit-ios

A simple iOS application that demonstrates how the end-to-end encryption works.
Swift
13
star
26

virgil-e3kit-kotlin

E3Kit is a security framework that simplifies work with Virgil services and presents the easiest way to add full end-to-end security to your chat application to become HIPAA and GDPR compliant and more.
Kotlin
12
star
27

demo-e3kit-android

A simple Android application that demonstrates how the end-to-end encryption works.
Kotlin
11
star
28

virgil-webrtc-qt-demo

C++
11
star
29

virgil-sdk-python

Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.
Python
10
star
30

virgil-sdk-php

Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.
PHP
10
star
31

virgil-purekit-go

PureKit Golang is a security framework that allows developers to protect users' passwords and sensitive personal information in a database from data breaches and both online and offline attacks and make stolen passwords useless even if a database is breached.
Go
10
star
32

virgil-sdk-go

Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.
C
9
star
33

virgil-messenger-qt

Virgil Security simple client/server example for *nix platforms
C++
9
star
34

virgil-crypto-python

Virgil Python Crypto Library is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant.
Python
9
star
35

demo-iotkit-nix

The Demo is based on Virgil IoTKit and its dev tools to demonstrate secure IoT devices development in action.
C
8
star
36

virgil-e3kit-flutter

Kotlin
8
star
37

virgil-purekit-java

PureKit SDK allows developers to protect users' passwords and sensitive personal information in a database from data breaches and both online and offline attacks and make stolen passwords useless even if a database is breached.
Java
8
star
38

virgil-pythia-go

Virgil Pythia SDK allows developers to implement Pythia protocol to create breach-proof passwords, immune to offline and online attacks.
Go
8
star
39

virgil-pass-plugins

Plugins that implement Virgil Cryptography
JavaScript
7
star
40

demo-backend-nodejs

A sample backend that demonstrates how to generate a Virgil JWT using JavaScript SDK
JavaScript
7
star
41

virgil-crypto-ruby

Virgil Ruby Crypto Library is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant.
Ruby
7
star
42

virgil-pure-wordpress

Free Wordpress Plugin based on a powerful and revolutionary cryptographic technology that protects user passwords from data breaches and both online and offline attacks.
PHP
6
star
43

virgil-mail

Virgil Mail plugin for OS X
Objective-C
6
star
44

virgil-passport-pythia

Passport strategy for authenticating with the Virgil Pythia PRF service
TypeScript
6
star
45

virgil-services-auth

Go
6
star
46

sample-backend-go

A sample backend that demonstrates how to generate a Virgil JWT using Go SDK
Go
6
star
47

virgil-mariadb-demo

A simple web application that illustrates how Virgil PureKit can be used with MariaDB to store and share data in the most secure way
Java
6
star
48

demo-twilio-chat-android

A simple Android application that demonstrates how the end-to-end encryption (E2EE) works in chat messaging use case. The application uses Twilio as a messaging provider.
Kotlin
6
star
49

demo-encryption-js

A single page React application with Node.js backend demonstrating the use of Virgil Javascript SDK.
HTML
6
star
50

virgil-sdk-crypto-net

Virgil .NET/C# Crypto Library is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant.
C#
6
star
51

virgil-crypto-net

Virgil .NET Crypto Library is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant.
C#
5
star
52

virgil-sdk-ruby

Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.
Ruby
5
star
53

virgil-purekit-php

PureKit PHP SDK allows developers to protect users' passwords and sensitive personal information in a database from data breaches and both online and offline attacks and make stolen passwords useless even if a database is breached.
PHP
5
star
54

virgil-pythia

Virgil Pythia Library
C++
4
star
55

virgild

Go
4
star
56

virgil-cryptowrapper-x

Virgil Crypto library is a small, flexible and convenient wrapper for a variety of cryptographic algorithms. Includes asymmetric key generation, encryption/decryption of data, generation/verification of digital signatures, Pythia protocol and Double Ratchet protocol implementation.
Swift
4
star
57

virgil-purekit-net

PureKit SDK allows developers to protect users' passwords and sensitive personal information in a database from data breaches and both online and offline attacks and make stolen passwords useless even if a database is breached.
C#
4
star
58

virgil-pythia-node

Virgil Pythia SDK allows developers to implement Pythia protocol to create breach-proof passwords, immune to offline and online attacks.
TypeScript
4
star
59

virgil-keyknox-x

KeyKnox SDK allows developers to communicate with Virgil Keyknox Service to upload, download, and synchronize encrypted sensitive data (private keys) between different devices.
Swift
4
star
60

demo-nexmo-chat-android

A simple Web application that demonstrates how the end-to-end encryption works in chat messaging use case. The application uses Nexmo as a messaging provider.
Kotlin
3
star
61

VirgilSecurity.github.io

A site for Virgil Security Reference APIs
HTML
3
star
62

virgil-iot-bsp

Contains public headers of IOT platforms.
C
3
star
63

virgil-messenger-x

A simple E2EE chat for iOS which uses Virgil Security services.
Swift
3
star
64

ionic-demo-healthcare

Simple web application that illustrates how distinct roles within a customer's application can be defined and used to restrict ePHI access in a HIPAA-compliant manner based on Ionic's Policy Engine
TypeScript
3
star
65

virgil-ratchet-kotlin

Virgil Security Ratchet SDK provides an implementation of the Double Ratchet algorithm, which is used by parties to exchange encrypted messages based on a shared secret key.
Kotlin
3
star
66

virgil-crypto-go

Virgil Go Crypto Library is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant.
3
star
67

virgil-keyknox-javascript

Keyknox SDK allows developers to communicate with Virgil Keyknox Service to upload, download, and synchronize encrypted sensitive data (private keys) between different devices.
TypeScript
3
star
68

virgil-sdk-pfs-x

Virgil PFS SDK Objective-C/Swift
Swift
3
star
69

virgil-sync

Secure data storage with Virgil Crypto library
C#
3
star
70

virgil-key-storage-rn

IStorageAdapter for React Native
TypeScript
2
star
71

demo-e3kit-web

JavaScript
2
star
72

demo-firebase-func

TypeScript
2
star
73

virgil-messenger-core

Shell
2
star
74

virgil-ratchet-x

Virgil Security Ratchet Objective-C/Swift SDK provides an implementation of the Double Ratchet algorithm, which is used by parties to exchange encrypted messages based on a shared secret key.
Swift
2
star
75

ionic-admin-nodejs

Ionic Admin Node.js SDK that enables developers to manage users, groups, data markings and data access policies in their Ionic tenant.
TypeScript
2
star
76

virgil-crypto-atmel

C
1
star
77

virgil-keyknox-kotlin

KeyKnox SDK allows developers to communicate with the Virgil Keyknox Service to upload, download, and synchronize encrypted sensitive data (private keys) between user's devices.
Kotlin
1
star
78

demo-e3kit-ios-twilio

Swift
1
star
79

demo-backend-java

A sample backend that demonstrates how to generate a Virgil JWT using Java SDK
Java
1
star
80

virgil-commkit-go

C
1
star
81

virgil-demo-chat

CSS
1
star
82

demo-e2ee-server-java

A simple Java server application that uses in end-to-end encryption (E2EE) use-case.
Java
1
star
83

virgil-mail-outlook

Vigril Mail plugin for Outlook
1
star
84

demo-nexmo-chat-server

Application API server for the Virgil Nexmo Demo Messaging app.
JavaScript
1
star
85

demo-twilio-sms-net

A simple Net Console application that demonstrates how to send encrypted message via SMS.
C#
1
star
86

virgil-cryptoapi-x

This framework provides Crypto API to separate VirgilSDK from concrete Crypto implementation
Swift
1
star
87

virgil-pythia-x

Virgil Pythia SDK allows developers to communicate with Virgil Pythia Service and implement Pythia protocol in order to generate a BrainKey.
Swift
1
star