{"id":19198574,"url":"https://github.com/virgilsecurity/demo-nexmo-chat-backend-java","last_synced_at":"2026-05-02T10:38:35.042Z","repository":{"id":146282686,"uuid":"170865151","full_name":"VirgilSecurity/demo-nexmo-chat-backend-java","owner":"VirgilSecurity","description":"This repository contains a sample backend code that demonstrates how to generate a Nexmo and Virgil JWTs using the Java/Android SDK.","archived":false,"fork":false,"pushed_at":"2019-10-04T10:27:48.000Z","size":46,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-01T18:39:02.173Z","etag":null,"topics":["backend","e3kit","java","nexmo"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"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","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-15T12:57:47.000Z","updated_at":"2019-10-04T10:27:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"10f4442e-e152-4306-8a68-26b38d4a578b","html_url":"https://github.com/VirgilSecurity/demo-nexmo-chat-backend-java","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/VirgilSecurity/demo-nexmo-chat-backend-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fdemo-nexmo-chat-backend-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fdemo-nexmo-chat-backend-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fdemo-nexmo-chat-backend-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fdemo-nexmo-chat-backend-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VirgilSecurity","download_url":"https://codeload.github.com/VirgilSecurity/demo-nexmo-chat-backend-java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fdemo-nexmo-chat-backend-java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32531742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["backend","e3kit","java","nexmo"],"created_at":"2024-11-09T12:22:41.316Z","updated_at":"2026-05-02T10:38:35.026Z","avatar_url":"https://github.com/VirgilSecurity.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sample Java Backend for Nexmo\n\nThis repository contains a sample backend code that demonstrates how to generate a Virgil JWT using the [Java/Android SDK](https://github.com/VirgilSecurity/virgil-sdk-java-android)\n\n\u003e Do not use this authentication in production. Requests to a /virgil-jwt endpoint must be allowed for authenticated users. Use your application authorization strategy.\n\n## Prerequisites\n* Java Development Kit (JDK) 8+\n\nFor IntelliJ IDEA Ultimate run:\n* IntelliJ IDEA Ultimate 2018.3.3+\n\u003e If you have Community version of IDEA - go to `Building a Jar` section.\n\nFor building a jar:\n* Maven 3+\n\n## IntelliJ IDEA Ultimate run\n- git clone https://github.com/VirgilSecurity/demo-nexmo-chat-backend-java\n- Open IntelliJ IDEA -\u003e File -\u003e New -\u003e Project from Existing Sources, locate `demo-nexmo-chat-backend-java` and click `open`\n- Select `Import project from external model` -\u003e `Maven`, go `next` till `Please select project SDK` page\n- Select in list of available JDKs `1.8.xxx` version or greater. If you haven't JDK of `1.8.xxx` version [install](https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) it. `Finish` setup.\n- Fill in your [credentials](#get-virgil-credentials) into the `demo-nexmo-chat-backend-java/src/main/resources/`[`application.properties`](https://github.com/VirgilSecurity/demo-nexmo-chat-backend-java/blob/master/src/main/resources/application.properties) file.\n- Run application\n\nIf server started successfully you will see in the end of logs:\n```\n: Tomcat started on port(s): 3000 (http)\n: Started ServerApplication\n```\n\n\u003e If you get error `Error:java: javacTask: source release 8 requires target release 1.8` go to IntelliJ IDEA -\u003e Preferences -\u003e Build, Execution, Deployment -\u003e Compiler -\u003e Java Compiler and select `8` in `Project bytecode version` field.\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- Create new E2EEv5 application;\n- Create new API Key and copy given private key;\n\nTo generate a JWT the following values are required from the steps above:\n\n| Variable Name                     | Description                    |\n|-----------------------------------|--------------------------------|\n| virgil.app.id                     | ID of your Virgil Application. |\n| virgil.app.private_key            | Private key of your APP key that is used to sign the JWTs. |\n| virgil.app.key_id                 | ID of your APP key. A unique string value that identifies your account in the Virgil Cloud. |\n\n- Replace credentials in [`application.properties`](https://github.com/VirgilSecurity/demo-nexmo-chat-backend-java/blob/master/src/main/resources/application.properties) with yours.\n\n## Get Nexmo Credentials\n\n - Register on https://developer.nexmo.com/\n - [Create Nexmo Application](https://developer.nexmo.com/tutorials/client-sdk-generate-test-credentials#create-a-nexmo-application) and remember your generated `private.key` path\n - Replace the \u003cYOUR_APP_ID\u003e in [`application.properties`](https://github.com/VirgilSecurity/demo-nexmo-chat-backend-java/blob/master/src/main/resources/application.properties) with your `app id` from the created app above:\n ```bash\n Application created: aaaaaaaa-bbbb-cccc-dddd-0123456789ab\n ```\n - Rename your Nexmo `private.key` to `virgilnexmodemo_private.key`\n - Put it near `application.properties` file to the [resourses folder](https://github.com/VirgilSecurity/demo-nexmo-chat-backend-java/blob/master/src/main/resources/)\n\n## Building a Jar\n\nPossibly, you want to build a Jar to deploy it on a remote server (e.g. [Now](https://zeit.co/now), [Heroku](https://www.heroku.com/)).\n\n### Clone\n\nClone the repository from GitHub.\n\n```\n$ git clone https://github.com/VirgilSecurity/e3kit-kotlin.git\n```\n\n### Build sources\n\n```\n$ mvn clean package -DskipTests\n```\n\nJAR file will be build in `target` directory.\n\n### Run the Server\n\nRun this command from the project's root folder:\n\n```\n$ java -jar target/server.jar\n```\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\nYou can verify the server with a command:\n\n```bash\n$ curl -X POST -H \"Content-Type: application/json\" \\\n  -d '{\"identity\":\"my_identity\"}' \\\n  http://localhost:3000/authenticate\n```\n\nThe response should looks like:\n\n```json\n{\"authToken\":\"my_identity-b5ba1680-4d5c-4b2e-9890-a0500d3c9bfe\"}\n```\n\n## Specification\n\n### /auth/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### /auth/virgil-jwt endpoint\nThis endpoint checks whether a user is authorized 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### /auth/nexmo-jwt endpoint\nThis endpoint checks whether a user is authorized by an authorization header. It takes user's `authToken`, finds related user identity and generates a `nexmoToken` (which is [JSON Web Token](https://jwt.io/)) with this `identity` in a payload. Use this token to make authorized api calls to Nexmo services. \n\u003e Current implementation provides only `/v1/sessions/**` and `/v1/conversations/**` ACLs (It's enough for text chat). You can modify this server to suit your needs for example passing ACLs as a query parameters to GET request and then add requested ACLs to you JWT. \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    \"nexmoToken\": \"string\"\n}\n```\n\n### /users/create endpoint\nThis endpoint checks whether a user is authorized by an authorization header. It [creates a user](https://developer.nexmo.com/api/conversation#createUser) on the `Nexmo` service and returns user's `id` and `reference`.\n\n```http\nPOST https://localhost:3000/authenticate HTTP/1.1\nContent-type: application/json;\nAuthorization: Bearer \u003cauthToken\u003e\n\n{\n    \"name\": \"string\",\n    \"display_name\": \"string\"\n}\n\nResponse:\n\n{\n    \"id\": \"string\",\n    \"href\": \"string\"\n}\n```\n\n## Virgil JWT Generation\nTo generate JWT, you need to use the `JwtGenerator` class from the SDK.\n\n```Java\npublic JwtGenerator jwtGenerator() throws CryptoException {\n    VirgilCrypto crypto = new VirgilCrypto();\n    PrivateKey privateKey = crypto.importPrivateKey(ConvertionUtils.base64ToBytes(this.appKey));\n    AccessTokenSigner accessTokenSigner = new VirgilAccessTokenSigner();\n\n    JwtGenerator jwtGenerator = new JwtGenerator(appId, privateKey, appKeyIdentifier,\n        TimeSpan.fromTime(1, TimeUnit.HOURS), accessTokenSigner);\n\n    return jwtGenerator;\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 [AuthenticationService.java](src/main/java/com/virgilsecurity/demo/server/service/AuthenticationService.java) file.\n\n\n\n## License\n\nThis library is released under the [3-clause BSD License](LICENSE.md).\n\n## Support\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-nexmo-chat-backend-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvirgilsecurity%2Fdemo-nexmo-chat-backend-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirgilsecurity%2Fdemo-nexmo-chat-backend-java/lists"}