Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/virgilsecurity/demo-nexmo-chat-server
Application API server for the Virgil Nexmo Demo Messaging app.
https://github.com/virgilsecurity/demo-nexmo-chat-server
api chat cryptography demo encryption messenger nexmo server
Last synced: 8 days ago
JSON representation
Application API server for the Virgil Nexmo Demo Messaging app.
- Host: GitHub
- URL: https://github.com/virgilsecurity/demo-nexmo-chat-server
- Owner: VirgilSecurity
- Created: 2018-01-05T15:47:55.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T10:35:50.000Z (almost 2 years ago)
- Last Synced: 2024-04-08T09:10:39.366Z (7 months ago)
- Topics: api, chat, cryptography, demo, encryption, messenger, nexmo, server
- Language: JavaScript
- Homepage: https://github.com/VirgilSecurity/demo-nexmo-chat-android
- Size: 193 KB
- Stars: 1
- Watchers: 9
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Virgil Nexmo Demo Chat API v2 Sample Backend
Application API server for the [Virgil Nexmo In-app Messaging Demo app](https://github.com/VirgilSecurity/demo-nexmo-chat-android). Its primary purpose is to register users' Virgil Cards on Virgil's Cards service and generate JWTs for users to access Nexmo and Virgil APIs. This server
is intended for demonstration purposes only, it does not implement request authentication strategy. Feel free to implement your own auth tech and/or copy the code into your own backend.## Contents
* [Deployment](#deployment)
* [Pre-requisites](#pre-requisites)
* [Setup instructions](#setup-instructions)
* [Endpoints](#endpoints)
* [POST /users](#post-users)
* [GET /users](#get-users)
* [POST /conversations](#post-conversations)
* [PUT /conversations](#put-conversations)
* [GET /nexmo-jwt](#get-nexmo-jwt)
* [GET /virgil-jwt](#get-virgil-jwt)
* [Errors](#errors)## Deployment
### Pre-requisites
* Ensure you have [Node.js](https://nodejs.org/en/) >= 8 installed
* Create a free [Virgil Security](https://dashboard.virgilsecurity.com/) account
* Create a free [Nexmo](https://dashboard.nexmo.com/) account
* Install the Nexmo CLI (note the `@beta` tag):
```sh
npm install -g nexmo-cli@beta
```
Setup the CLI to use your Nexmo API Key and API Secret. You can get these from the
[settings](https://dashboard.nexmo.com/settings) page in the Nexmo Dashboard.
```sh
nexmo setup api_key api_secret
```### Setup instructions
* Clone this Node sample server repo to your disk and step into the project's folder
```sh
git clone https://github.com/VirgilSecurity/demo-nexmo-chat-server.git
cd demo-nexmo-chat-server
```
* Create a Nexmo Application
```sh
nexmo app:create "My Stitch App" https://example.com/answer https://example.com/event --type=rtc --keyfile=private.key
```
* Install the Virgil Node sample server package and run setup. The set setup will ask you a few questions...
```sh
npm install
npm run setup
```
* To provide the first input, create an **END-TO-END ENCRYPTION** Application in the Virgil Security [Dashboard](https://dashboard.virgilsecurity.com/apps/new) and copy the APP ID here:
```sh
? Enter your Virgil Security Application ID [paste Virgil APP ID here]
```
* Go back to the Virgil Dashboard [API Keys page and create one](https://dashboard.virgilsecurity.com/api-keys), it will be copied to your clipboard.
```sh
? Enter your Virgil Security API Key private key [paste it here]
```* Now, on the Virgil API keys page, find your new API key in the list and copy its API KEY ID.
```sh
? Enter your Virgil Security API Key ID [paste it here]
```
* Get your [Nexmo API keys](https://dashboard.nexmo.com/getting-started-guide) and complete the rest of the questions:
```sh
? Enter the path to your Nexmo app conifg file (.nexmo-app) [simply hit enter]
? Enter your Nexmo API Key [paste your Nexmo API key]
? Enter your Nexmo API Secret [paste your Nexmo API secret]
```
* Now the Virgil node backend server is ready to start:
```sh
npm start
```
* You can test it at http://localhost:3000Leave the server running and continue your mobile app setup: [Android](https://github.com/VirgilSecurity/demo-nexmo-chat-android) iOS & JS coming soon
## Endpoints
Use this part of the readme to understand what this backend sample does and how it fits in with your own backend.
### POST /users
An endpoint to register new user. Expects a _Raw Card_ in base64 string form as its only parameter.
The raw card must have unique identity, attempt to register a card with duplicate identity will result in
`400 BadRequest` error.
**Request**
```json
{
"raw_card_string": "eyJjb250ZW50X3NuYXBzaG90IjoiZXlKcFpHVnVkR2...k9In19fQ=="
}
```**Response**
If request is successful, an object representing a [Nexmo user](https://developer.nexmo.com/stitch/in-app-messaging/guides/simple-conversation)
is returned along with the base64 string representation of the user's Virgil Card and two JWTs for Nexmo and Virgil
APIs:> Request must include `Content-Type: "application/json"` header
```json
{
"user": {
"id": "USR-aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"href": "http://conversation.local/v1/users/USR-aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"virgil_card": "eyJjb250ZW50X3NuYXBzaG90IjoiZXlKcFpHVnVkR2...k9In19fQ=="
},
"nexmo_jwt": "xxxxx.yyyyy.zzzzz",
"virgil_jwt": "qqqqq.bbbbb.ddddd"
}
```
You can then use the `CardManager` from virgil sdk to `import` a Virgil Card from this string. The `nexmo_jwt` and
`virgil_jwt` can be used to initialize the appropriate API client.### GET /users
An endpoint to retrieve a list of users.
**Response**
```json
[
{
"name": "Dillon",
"id": "USR-aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"href": "http://conversation.local/v1/users/USR-aaaaaaaa-bbbb-cccc-dddd-0123456789ab"
}
]
```### POST /conversations
An endpoint to create a new [Nexmo Conversation](https://developer.nexmo.com/stitch/in-app-messaging/guides/simple-conversation)
**Request**
```json
{
"display_name": "My new conversation"
}
```**Response**
```json
{
"id": "CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"href": "http://conversation.local/v1/conversations/CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab"
}
```
### PUT /conversationsAn endpoint to add a user to a conversation.
**Request**
```json
{
"conversation_id": "CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"user_id": "USR-aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"action": "join"
}
```Parameter action must be "join" to add the user to the conversation. Other types of actions - TBD.
**Response**
```json
{
"id": "MEM-aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"user_id": "USR-aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"state": "JOINED",
"timestamp": { "joined": "2018-01-15T15:17:59.248Z" },
"channel": { "type": "app" },
"href": "http://conversation.local/v1/conversations/CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab/members/MEM-aaaaaaaa-bbbb-cccc-dddd-0123456789ab"
}
```### GET /nexmo-jwt?identity=[YOUR_USER_IDENTITY]
An endpoint to obtain an access token for the Nexmo API. The URL must include a query parameter named `identity` that is the identity of the user to issue the token for.
**Response**
```json
{
"jwt": "xxxxx.yyyyy.zzzzz"
}
```### GET /virgil-jwt
An endpoint to obtain an access token for the Virgil Security API. The URL must include a query parameter named `identity` that is the identity of the user to issue the token for.
**Response**
```json
{
"jwt": "qqqqq.bbbbb.ddddd"
}
```## Errors
Application uses standard HTTP response codes:
```
200 - Success
400 - Request error
500 - Server error
```Additional information about the error is returned in response body as JSON object:
```json
{
"status": 500,
"error_code": 50000,
"message": "Message containing error details"
}
```