{"id":19198449,"url":"https://github.com/virgilsecurity/demo-twilio-backend-nodejs","last_synced_at":"2026-03-08T20:32:54.396Z","repository":{"id":41786828,"uuid":"47191000","full_name":"VirgilSecurity/demo-twilio-backend-nodejs","owner":"VirgilSecurity","description":"A sample backend that demonstrates how to generate a Virgil JWT and Twilio token used for authentication with the Virgil and Twilio services","archived":false,"fork":false,"pushed_at":"2022-12-30T19:57:53.000Z","size":6321,"stargazers_count":127,"open_issues_count":10,"forks_count":21,"subscribers_count":31,"default_branch":"master","last_synced_at":"2024-07-31T19:38:33.562Z","etag":null,"topics":["chat","crypto","cryptography","demo","encryption","end-to-end-encryption","jwt","messenger","sample-backend","secure-the-future","secured-by-virgil","twilio","twilio-chat"],"latest_commit_sha":null,"homepage":"https://developer.virgilsecurity.com/docs/use-cases/v5/encrypted-communication-for-twilio","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VirgilSecurity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-01T13:23:53.000Z","updated_at":"2023-05-27T15:35:20.000Z","dependencies_parsed_at":"2023-01-31T15:15:58.372Z","dependency_job_id":null,"html_url":"https://github.com/VirgilSecurity/demo-twilio-backend-nodejs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fdemo-twilio-backend-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fdemo-twilio-backend-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fdemo-twilio-backend-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fdemo-twilio-backend-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VirgilSecurity","download_url":"https://codeload.github.com/VirgilSecurity/demo-twilio-backend-nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249094160,"owners_count":21211825,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chat","crypto","cryptography","demo","encryption","end-to-end-encryption","jwt","messenger","sample-backend","secure-the-future","secured-by-virgil","twilio","twilio-chat"],"created_at":"2024-11-09T12:22:05.066Z","updated_at":"2026-03-08T20:32:54.348Z","avatar_url":"https://github.com/VirgilSecurity.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twilio Sample Backend for Node.js\n\nThis 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.\n\n\u003e 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.\n\n## Prerequisites\n\n- [NodeJS](https://nodejs.org) from 10 to 13\n\n## Set up and run demo\n\n### Clone\n\nClone the repository from GitHub.\n\n```\n$ git clone https://github.com/VirgilSecurity/twilio-sample-backend-nodejs.git\n```\n\n### Get Virgil Credentials\n\nIf you don't have an account yet, [sign up for one](https://dashboard.virgilsecurity.com/signup) using your e-mail. \n\n#### You can download a ready-to-use .env file\n\n1. Navigate to the Virgil Dashboard -\u003e Your Application -\u003e E3Kit Section.\n2. Generate `.env` in the **.env file** section.\n3. Download the generated file, paste it into the project root folder and rename it to `.env`.\n\n#### Or you can add the parameters manually:\n\nTo generate a Virgil JWT the following values are required:\n\n| Variable Name                     | Description                    |\n|-----------------------------------|--------------------------------|\n| APP_ID                   | ID of your Virgil Application. |\n| APP_KEY                  | Private key of your App that is used to sign the JWTs. |\n| APP_KEY_ID               | ID of your App Key. A unique string value that identifies your account in the Virgil Cloud. |\n\n1. Copy and rename `.env.example` to `.env`.\n2. Create Application in the Virgil Dashboard, copy its `APP_ID` to the `.env` file;\n3. Create App Key and save its private key value to `APP_KEY` line in the `.env` file;\n4. Copy ID of the created key to `APP_KEY_ID` line in the `.env` file;\n\n### Get Twilio Credentials\n\nTo generate a Twilio JWT the following values are required:\n\n| Variable Name                     | Description                    |\n|-----------------------------------|--------------------------------|\n| TWILIO_ACCOUNT_SID                | Your primary Twilio account identifier - [find this in the console here.](https://www.twilio.com/console)        |\n| TWILIO_API_KEY_SID                    | SID of Twilio Api Key. Used for authentication on Twilio services. Generated with TWILIO_API_SECRET|\n| TWILIO_API_SECRET                 | Twilio API key secret: [generate one here](https://www.twilio.com/console/chat/runtime/api-keys) |\n| TWILIO_SERVICE_SID            | A service instance where all the data for our application is stored and scoped. [Generate one in the console here.](https://www.twilio.com/console/chat/dashboard) |\n\nAdd this parameters to your `.env` file.\n\n### Install Dependencies and Run the Server\n\n```\n$ npm install\n$ npm run start\n```\nNow, use your client code to make a request to get a JWT from the sample backend that is working on http://localhost:3000.\n\nAlong 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`](https://github.com/VirgilSecurity/demo-twilio-backend-nodejs/tree/master/public) directory.\n\n\u003cimg  src=\"img/demo.png\" alt=\"Demo screenshot\"\u003e\n\n## Specification\n\n### /authenticate endpoint\nThis endpoint is an example of users authentication. It takes user `identity` and responds with unique token.\n\n```http\nPOST https://localhost:3000/authenticate HTTP/1.1\nContent-type: application/json;\n\n{\n    \"identity\": \"string\"\n}\n\nResponse:\n\n{\n    \"authToken\": \"string\"\n}\n```\n\n### /virgil-jwt endpoint\nThis 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](https://jwt.io/)) with this `identity` in a payload. Use this token to make authorized API calls to Virgil Cloud.\n\n```http\nGET https://localhost:3000/virgil-jwt HTTP/1.1\nContent-type: application/json;\nAuthorization: Bearer \u003cauthToken\u003e\n\nResponse:\n\n{\n    \"virgilToken\": \"string\"\n}\n```\n\n### /twilio-jwt endpoint\nSame as Virgil token endpoint Twilio endpoint should be protected and responds with `twilioToken`.\n\n```http\nGET https://localhost:3000/twilio-jwt HTTP/1.1\nContent-type: application/json;\nAuthorization: Bearer \u003cauthToken\u003e\n\nResponse:\n\n{\n    \"twilioToken\": \"string\"\n}\n```\n\n## Virgil JWT Generation\nTo generate a Virgil JWT, you need to use the `JwtGenerator` class from the Virgil SDK.\n\n```js\nconst virgilCrypto = new VirgilCrypto();\n\nconst generator = new JwtGenerator({\n  appId: process.env.APP_ID,\n  apiKeyId: process.env.API_KEY_ID,\n  apiKey: virgilCrypto.importPrivateKey(process.env.API_PRIVATE_KEY),\n  accessTokenSigner: new VirgilAccessTokenSigner(virgilCrypto)\n});\n\n```\n\nThen you need to provide an HTTP endpoint which will return the JWT with the user's identity as a JSON.\n\nFor more details take a look at the [virgilToken.js](api/virgilToken.js) file.\n\n## License\n\nThis library is released under the [3-clause BSD License](LICENSE.md).\n\n## Support\n\nOur developer support team is here to help you. Find out more information on our [Help Center](https://help.virgilsecurity.com/).\n\nYou can find us on [Twitter](https://twitter.com/VirgilSecurity) or send us email support@VirgilSecurity.com.\n\nAlso, get extra help from our support team on [Slack](https://virgilsecurity.com/join-community).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirgilsecurity%2Fdemo-twilio-backend-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvirgilsecurity%2Fdemo-twilio-backend-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirgilsecurity%2Fdemo-twilio-backend-nodejs/lists"}