Skip to content

Commit cd16e18

Browse files
authored
feat: CHARTS-7418 Add embedding examples for realm-web package (#70)
1 parent 07d6a54 commit cd16e18

File tree

53 files changed

+14092
-530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+14092
-530
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ yarn add @mongodb-js/charts-embed-dom
3434

3535
- [Getting started with the MongoDB Charts SDK](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/charts/unauthenticated)
3636
- [Getting started with custom JWT authentication](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/charts/authenticated-custom-jwt)
37-
- [Getting started with Realm authentication](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/charts/authenticated-realm)
37+
- [Getting started with App Services authentication via Realm Web SDK](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/charts/authenticated-realm-web)
3838
- [Getting started with Google authentication](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/charts/authenticated-google)
3939
- [Getting started with click events](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/charts/click-events-basic)
4040
- [Interactive filtering using click events](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/charts/click-events-filtering)
@@ -45,6 +45,6 @@ yarn add @mongodb-js/charts-embed-dom
4545

4646
- [Embedding an unauthenticated dashboard](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/dashboard/unauthenticated)
4747
- [Dashboard embedding with custom JWT authentication](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/dashboard/authenticated-custom-jwt)
48-
- [Dashboard embedding with Realm authentication](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/dashboard/authenticated-realm)
48+
- [Dashboard embedding with App Services authentication via Realm Web SDK](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/dashboard/authenticated-realm-web)
4949
- [Dashboard embedding with Google authentication](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/dashboard/authenticated-google)
5050
- [Accessing a Chart instance via Dashboard class](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/dashboard/unauthenticated-get-chart)

examples/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
MongoDB Charts allows you to create visualizations of your MongoDB data using a simple web interface. You can view the visualizations within the Charts UI, or you can use the Embedding feature to render the charts in an external web application.
44

5-
Charts can be embedded either using a simple IFRAME snippet, or by using the Charts Embedding SDK from your JavaScript code. When using the SDK, embedded charts can be either unauthenticated (meaning anyone who has the embed code can view the chart), or authenticated (whereby the user can only view the chart if they have an active authentication session linked to a Charts authentication provider).
5+
Charts can be embedded either using a simple IFRAME snippet, or by using the Charts Embedding SDK from your JavaScript code. When using the SDK, embedded charts can be either unauthenticated (meaning anyone who has access to the page where the chart is embedded can view the chart), or authenticated (whereby the user can only view the chart if they have an active authentication session linked to a Charts authentication provider).
66

77
This directory contains example applications making use of both unauthenticated and authenticated utilizations of the SDK. They are provided as a reference to kick start your development process. To run these examples, simply clone the directory, and run the following commands:
88

@@ -18,7 +18,7 @@ The [Unauthenticated](https://github.com/mongodb-js/charts-embed-sdk/tree/master
1818
Our **authenticated** examples are great references if you need help getting started creating Authenticated Embedded Charts. We have three examples, each tailored for the three Authentication Providers now available in MongoDB Charts. The three examples are:
1919

2020
- [Custom JWT](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/charts/authenticated-custom-jwt)
21-
- [MongoDB Realm](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/charts/authenticated-realm)
21+
- [Atlas App Services](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/charts/authenticated-realm-web)
2222
- [Google](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/charts/authenticated-google)
2323

2424
If you'd like to build **interactive** charts, we have two examples showing this capability:
@@ -40,7 +40,7 @@ If your dashboard needs some privacy, you can look at our authenticated examples
4040

4141

4242
- [Custom JWT](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/dashboard/authenticated-custom-jwt)
43-
- [MongoDB Realm](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/dashboard/authenticated-realm)
43+
- [Atlas App Services](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/dashboard/authenticated-realm-web)
4444
- [Google](https://github.com/mongodb-js/charts-embed-sdk/tree/master/examples/dashboard/authenticated-google)
4545

4646

examples/charts/authenticated-custom-jwt/README.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
MongoDB Charts allows you to create visualizations of your MongoDB data using a simple web interface. You can view the visualizations within the Charts UI, or you can use the Embedding feature to render the charts in an external web application.
88

9-
Charts can be embedded either using a simple IFRAME snippet, or by using the Charts Embedding SDK from your JavaScript code. When using the SDK, embedded charts can be either unauthenticated (meaning anyone who has the embed code can view the chart), or authenticated (whereby the user can only view the chart if they have an active authentication session linked to a Charts authentication provider).
9+
Charts can be embedded either using a simple IFRAME snippet, or by using the Charts Embedding SDK from your JavaScript code. When using the SDK, embedded charts can be either unauthenticated (meaning anyone who has access to the page where the chart is embedded can view the chart), or authenticated (whereby the user can only view the chart if they have an active authentication session linked to a Charts authentication provider).
1010

1111
This sample shows how to use the JavaScript Embedding SDK to render **authenticated** embedded charts, specifically via a custom jwt authentication. The sample app has its own authentication and token issuing logic. You may want to follow a similar approach if you are not integrating with an external authentication mechanism or your authentication is not based on JWTs. Alternatively, if you are using an existing authentication mechanism that issues JWTs, you can use those tokens to authenticate your chart rendering requests after configuring a Charts authentication provider that can validate the JWT.
1212

@@ -33,24 +33,39 @@ _The following steps presume the use of npm, though yarn works as well._
3333

3434
This sample is preconfigured to render a specific chart. You can run the sample as-is, or you can modify it to render your own chart by completing the following steps:
3535

36-
1. Log onto MongoDB Charts
36+
### Create chart to embed
37+
38+
1. Log onto MongoDB Charts.
3739

3840
2. If you haven't done so already, create a chart on any dashboard that you would like to embed.
3941

40-
3. Go to the Data Sources tab, find the data source that you are using on the chart, and choose External Sharing Options from the ... menu. Make sure that embedding is enabled for this data source and select '**Verified Signature Only**'
42+
### Enable data source for authenticated access
43+
44+
3. Go to the Data Sources tab found on the side panel.
45+
46+
4. Find the data source that you want to use on the chart by selecting the deployment, database and collection. Once found, click on the Manage button in the Data access section to access the Data source management page.
47+
48+
5. Make sure the "External users can view data in this data source" option is toggled on and "Allow authenticated data access" has been selected.
49+
50+
### Enable chart for embedded access
4151

42-
4. Find the chart you want to embed, click the **...** menu and select **Embed Chart**
52+
6. Go to the Dashboards tab on the side panel, and select the dashboard that contains the chart you wish to embed.
4353

44-
5. Ensure the Unauthenticated tab is selected and turn on '**Enable authenticated access**'
54+
7. Click the **...** menu and select **Embed chart**.
4555

46-
6. Note the Chart ID and the Chart Base URL, as you will need them for running the demo.
56+
8. Ensure the Authenticated tab is selected and turn on '**Enable authenticated access**'.
4757

48-
7. Close the menu and click on the Admin Settings button.
58+
9. Note the Chart ID and the Base URL, as you will need them for running the demo.
4959

50-
8. Under Embedding Authentication Providers, press the **Add New Provider** button
51-
9. Fill in the details like so:
60+
10. Close the menu.
5261

53-
![](https://i.imgur.com/8cS1iSJ.png)
62+
### Create authentication provider
63+
64+
11. Go to the Embedding tab on the side panel.
65+
66+
12. Ensure the "Authentication Settings" tab is selected and press the "Add" button in the Authentication providers section.
67+
68+
13. Fill in the details like so:
5469

5570
- Name: `Custom JWT` _Note, this is only for your convenience and can be named anything_
5671
- Provider: `Custom JSON Web Token`
@@ -69,8 +84,9 @@ This sample is preconfigured to render a specific chart. You can run the sample
6984
This should create a local server running the Charts demo. Open a web browser and navigate to `http://localhost:1234` in the url bar to see the sample. Along with this, a local jwt authentication server will be spun up on `http://localhost:8000`.
7085

7186
The hard coded credentials used in this demo are:
72-
username : `admin`
73-
password: `password`
87+
88+
- Username : `admin`
89+
- Password: `password`
7490

7591
## Next Steps
7692

examples/charts/authenticated-custom-jwt/package-lock.json

Lines changed: 14 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/charts/authenticated-custom-jwt/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
"build": "parcel build index.html"
99
},
1010
"dependencies": {
11-
"@mongodb-js/charts-embed-dom": "^2.1.0",
11+
"@mongodb-js/charts-embed-dom": "^2.3.0",
1212
"cors": "^2.8.5",
1313
"express": "^4.16.3",
1414
"jsonwebtoken": "^8.3.0",
15+
"parcel": "^1.12.4",
1516
"regenerator-runtime": "^0.13.3",
16-
"request": "^2.88.2",
17-
"parcel": "^1.12.4"
17+
"request": "^2.88.2"
1818
},
1919
"devDependencies": {
2020
"@babel/core": "^7.8.6",

examples/charts/authenticated-google/README.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
MongoDB Charts allows you to create visualizations of your MongoDB data using a simple web interface. You can view the visualizations within the Charts UI, or you can use the Embedding feature to render the charts in an external web application.
88

9-
Charts can be embedded either using a simple IFRAME snippet, or by using the Charts Embedding SDK from your JavaScript code. When using the SDK, embedded charts can be either unauthenticated (meaning anyone who has the embed code can view the chart), or authenticated (whereby the user can only view the chart if they have an active authentication session linked to a Charts authentication provider).
9+
Charts can be embedded either using a simple IFRAME snippet, or by using the Charts Embedding SDK from your JavaScript code. When using the SDK, embedded charts can be either unauthenticated (meaning anyone who has access to the page where the chart is embedded can view the chart), or authenticated (whereby the user can only view the chart if they have an active authentication session linked to a Charts authentication provider).
1010

1111
This sample shows how to use the JavaScript Embedding SDK to render **authenticated** embedded charts, specifically via configuring **Google** as an authentication provider. The sample app is already set up to authenticate with a Google Client ID hosted by the Charts Development team.
1212

@@ -39,30 +39,48 @@ This sample is pre-configured with a MongoDB-owned test Client ID. To use Google
3939

4040
Steps on how to configure a Project with Google and attain a Google Client ID can be found [here](https://developers.google.com/identity/sign-in/web/sign-in). You'll need to set the Origin and Redirect URIs to whatever you use in your application. In our sample, that is http://localhost:3000.
4141

42-
### Preparing your Chart for Embedding
42+
## Preparing your Chart for Embedding
4343

4444
This sample is preconfigured to render a specific chart. You can run the sample as-is, or you can modify it to render your own chart by completing the following steps:
4545

46+
### Create chart to embed
47+
4648
1. Log onto MongoDB Charts
4749

4850
2. If you haven't done so already, create a chart you would like to embed on any dashboard.
4951

50-
3. Go to the Data Sources tab on the left navigation column. Find the data source that you are using on the chart, and choose External Sharing Options from the ... menu. Make sure that embedding is enabled for this data source and select '**Authenticated Embedding Only**'
52+
### Enable data source for authenticated access
5153

52-
4. Go to the Admin Settings tab on the left navigation column. Under 'Embedding Authentication Providers', click 'Add New Provider'.
54+
3. Go to the Data Sources tab found on the side panel.
5355

54-
- Name your Provider e.g `Google`
55-
- Select the Google Provider.
56-
- Enter your Google Client ID
57-
- This should be the entire string `<encodedData>.apps.googleusercontent.com`
56+
4. Find the data source that you want to use on the chart by selecting the deployment, database and collection. Once found, click on the Manage button in the Data access section to access the Data source management page.
57+
58+
5. Make sure the "External users can view data in this data source" option is toggled on and "Allow authenticated data access" has been selected.
59+
60+
### Enable chart for embedded access
61+
62+
6. Go to the Dashboards tab on the side panel, and select the dashboard that contains the chart you wish to embed.
63+
64+
7. Find the chart you want to embed, click the **...** menu and select **Embed chart**
5865

59-
5. Go to the Dashboards tab on the left navigation column, and select the dashboard that contains the chart you wish to embed.
66+
8. Ensure the **Authenticated** tab is selected and turn on '**Enable authenticated access**'
6067

61-
6. Find the chart you want to embed, click the **...** menu and select **Embed Chart**
68+
9. Note the **Chart ID** and the **Base URL**, as you will need them for running the demo.
6269

63-
7. Ensure the Unauthenticated tab is selected and turn on '**Enable Authenticated access**'
70+
### Create authentication provider
6471

65-
8. Note the Chart ID and the Chart Base URL, as you will need them for running the demo.
72+
10. Go to the Embedding tab on the side panel.
73+
74+
11. Ensure the "Authentication Settings" tab is selected and press the "Add" button in the Authentication providers section.
75+
76+
12. Go to the Admin Settings tab on the left navigation column. Under 'Embedding Authentication Providers', click 'Add New Provider'.
77+
78+
13. Fill in the details like so:
79+
80+
- Name: `Google` _Note, this is only for your convenience and can be named anything you want here_
81+
- Provider: `Google`
82+
- Google Client ID: _See above for
83+
- This should be the entire string `<encodedData>.apps.googleusercontent.com`
6684

6785
## Running this Sample with your data
6886

0 commit comments

Comments
 (0)