Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

Commit fb69d71

Browse files
authored
Merge pull request #1097 from Bandwidth/GRAVITY-1030
GRAVITY-1030 Add documentation for the authentication of WebRTC In-AppCalling
2 parents ac1db84 + 4e8b132 commit fb69d71

File tree

6 files changed

+8555
-7864
lines changed

6 files changed

+8555
-7864
lines changed

site/docusaurus.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,8 @@ module.exports = {
241241
],
242242
"docusaurus-plugin-sass",
243243
],
244+
markdown: {
245+
mermaid: true,
246+
},
247+
themes: ['@docusaurus/theme-mermaid'],
244248
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
id: inAppAuthGuide
3+
title: Authentication for Global In-App Calling
4+
slug: /voice/guides/inAppCalling/authentication
5+
description: Authentication In-App Calling (WebRTC)
6+
keywords:
7+
- bandwidth
8+
- voice
9+
hide_title: false
10+
image: '@site/static/img/bw-icon.svg'
11+
---
12+
## Retrieving an access token
13+
14+
:::caution
15+
16+
The token should be retrieved from a server running in a secure environment and securely provided to clients. Client-side javascript does not have a mechanism for hiding these credentials so **DO NOT** place these directly in your client-side code.
17+
18+
Bandwidth accepts no responsibility for the loss of account credentials and any resulting network traffic, fraud, or undesired account access that results from failing to manage account access credentials in a completely secure manner.
19+
:::
20+
21+
22+
The process to retrieve an access token requires you to have your [WebRTC Credentials](./inAppGuide.mdx#generating-credentials-for-an-access-token) (ie. ClientID and ClientSecret), generated from the [Global Portal](https://login.voxbone.com/login). You will then be able to make a call to our token endpoint with these credentials.
23+
24+
```mermaid
25+
sequenceDiagram
26+
Application->>In-App Calling AuthServer: GET /api/v1/oauth2/token?scope=voice.webrtc <br> Headers: { Authorization: Basic PEJhc2ljIEF1dGggVXNlcm5hbWU+OjxCYXNpYyBBdXRoIFBhc3N3b3JkPg== }
27+
In-App Calling AuthServer->>In-App Calling AuthServer: Validate credentials
28+
In-App Calling AuthServer->>Application: 200 OK <br> {"access_token": "...", "access_token_id": "...", "token_type": "Bearer", "expires_in": 600}
29+
```
30+
### Request
31+
In order to retrieve the token, you will use Basic Authentication `ClientID:ClientSecret`. Below is a sample request:
32+
33+
```sh
34+
curl --request POST \
35+
--url https://id.voxbone.com/api/v1/oauth2/token \
36+
--header 'Authorization: Basic PEJhc2ljIEF1dGggVXNlcm5hbWU+OjxCYXNpYyBBdXRoIFBhc3N3b3JkPg==' \
37+
--header 'Content-Type: application/x-www-form-urlencoded' \
38+
--data grant_type=client_credentials \
39+
--data scope=voice.webrtc
40+
```
41+
Now that we've shown the request, let's break down the parts of the API call.
42+
43+
- **url** `https://id.voxbone.com/api/v1/oauth2/token` - This is the In-App Calling AuthServers's `token_endpoint`.
44+
- **Headers**
45+
- **Authorization** - Authentication is required. You **MUST** provide your `ClientID` and `ClientSecret` using a Base64-encoded header with the `Basic` authentication scheme. The header value before encoding should take the form `Basic <ClientID>:<ClientSecret>`.
46+
- **Content-Type** - You **MUST** use `application/x-www-form-urlencoded`. This will URL encode (aka percent-encode) the parameters making them into `key=value` pairs which will be separated by an ampersand `&`.
47+
- **Body**
48+
- `grant_type` Currently, we only support `client_credentials` OAuth2 `grant_type`.
49+
- `scope` You **MUST** pass the value of `voice.webrtc` to have permissions for the WebRTC Gateway.
50+
51+
### Response
52+
An example response is:
53+
```
54+
{
55+
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImFsb2hvbW9yYSJ9.e30.kl3HYFQIcP4xZd78wUkdXxntxBu1d7b5ZCt99qVObC-gUZd5KSq2J7Q5rDb2LjP1_WVndcLQSqCoq3Anvp03hJWM6mamZL3dWHxjGLwkrIlzmNx9ZFGhTGIEsYLyaQqy8MonWYw2mJ4Z0APEfTVbTBHNIGrm_9GT6rIkdOwQFM-XgH1Tau4JbpFJun3n6o15WTgjzdEj9fIwd385CPwL-pAmOiozbYWUEzgqkXjSGHI11hiLDu-tv_8Ds06Cx4iCnL1F6_dFrnpD3CF0i6JJYVrvLmi6vgzoxp9YEIRBwaOZTSuYuYt03SQfbMZy8L2Z71sRKLLGt3TrxgtwyjefpQ",
56+
"access_token_id": "a5xA3xMKEggGwvpSLtk2lRb",
57+
"token_type": "Bearer",
58+
"expires_in": 600
59+
}
60+
```
61+
62+
Let's see what each item in the response object is meant for:
63+
- `access_token`: This is the JSON Web Token (JWT) that will be passed in the Authorization header of the requests to the In-App Calling API. **NOTE:** The example above does not contain a valid token and cannot be used to actually authenticate.
64+
- `access_token_id`: This will be the ID of the access token to prevent tokens from being re-used. It will be the same as the `jti` claim within the access token.
65+
- `token_type`: This is used to identify the type of token and also the prefix to be used in the Authorization header.
66+
- `expires_in`: This is the length of time, in seconds, before a token expires. In the example above the value is `600`. This means the token will be valid for 600 seconds (10 minutes) before it expires. You should use the token until 10-30 seconds before expiration, at which point you **MUST** request a new token in the same manner as described above.
67+
68+
### Using the Access Token
69+
70+
Once you have obtained the token you can perform authenticated requests to the WebRTC Gateway using the [Bandwidth WebRTC SDK](./inAppGuide.mdx#sdks).

site/global-guides/voice/inAppGuide.mdx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,13 @@ The following steps can be followed to generate your credentials:
9191

9292
![Generating WebRTC Credentials](@site/static/img/docs-diagrams/voice/in-app-credentials.png)
9393

94-
Once you have generated your credentials you can call our identity services endpoint. Please refer to here for more information.
94+
Once you have generated your credentials you can retrieve an access token from our token API.
9595

9696
:::note
97-
The scope must be **voice.webrtc** to generate an access token to use for in-app calling.
97+
The token **MUST** contain the scope **voice.webrtc** to use for in-app calling.
9898
:::
9999

100-
As the token will be visible within your application we strongly advise to only use this scope. The token should be fetched from a server running in a secure environment, and provided to clients in a secure manner.
101-
102-
We recommend regenerating the token every 30 seconds before expiry. It is not advisable to regenerate the token for every in-app voice call as this will create an unnecessary delay in the call being connected.
103-
104-
Bandwidth accepts no responsibility for the loss of account credentials and any resulting network traffic, fraud, or undesired account access that results from failing to manage account access credentials in a completely secure manner. Minting of tokens is not included as a client SDK capability for the above reason.
100+
Please refer to the documentation on [how to retrieve an access token](./authentication.mdx) for more information.
105101

106102
## Resources
107103

@@ -257,4 +253,4 @@ Once a call has been established, this method could be used to mute the audio.
257253

258254
#### activeCall.isLocalHold()
259255

260-
Returns a boolean value indicating whether the call is currently held as the result of an activeCall.hold(true) action.
256+
Returns a boolean value indicating whether the call is currently held as the result of an activeCall.hold(true) action.

site/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@docusaurus/core": "^2.4.1",
2121
"@docusaurus/plugin-google-gtag": "^2.4.1",
2222
"@docusaurus/preset-classic": "^2.4.1",
23+
"@docusaurus/theme-mermaid": "^2.4.1",
2324
"@types/react": "^17.0.0",
2425
"bandwidth-redoc": "^1.4.0",
2526
"buffer": "^6.0.3",

site/sidebarsGlobalGuides.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
label: "Voice",
1111
items: [
1212
"voice/inAppGuide",
13+
"voice/inAppAuthGuide"
1314
]
1415
}
1516
]

0 commit comments

Comments
 (0)