Browse Source

DOC-2582: Add `exportword`, `importword` and `exportpdf` JWT authentication guides for (Node.js). (#3517)

* DOC-2582: Export to PDF with JWT authentication (Node.js) Guide.

* Update modules/ROOT/pages/export-to-pdf-with-jwt-authentication-nodejs.adoc

* Update modules/ROOT/pages/export-to-pdf-with-jwt-authentication-nodejs.adoc

* Update modules/ROOT/pages/export-to-pdf-with-jwt-authentication-nodejs.adoc

* DOC-2582: Add importword and exportword guide.

* DOC-2582: Update comments in the html sorce examples.

* DOC-2582: Replace duplicated content with partials, cleaned up lvl headings in sidebar.

* Update modules/ROOT/pages/export-to-pdf-with-jwt-authentication-nodejs.adoc

* Update modules/ROOT/pages/export-to-word-with-jwt-authentication-nodejs.adoc

* Update modules/ROOT/pages/importword-with-jwt-authentication-nodejs.adoc

* DOC-2582: Update folder structure and naming, added JWT setup, fixed nav.adoc.

* DOC-2582: Copy edits, fix typos.

* Update modules/ROOT/pages/export-to-pdf-with-jwt-authentication-nodejs.adoc

Co-authored-by: Farzad Hayat <farzad.hayatbakhsh@tiny.cloud>

* Update modules/ROOT/partials/auth/document-converters/server-setup-jwt.adoc

Co-authored-by: Farzad Hayat <farzad.hayatbakhsh@tiny.cloud>

* Update modules/ROOT/pages/exportword.adoc

Co-authored-by: Farzad Hayat <farzad.hayatbakhsh@tiny.cloud>

* Update modules/ROOT/partials/auth/document-converters/initial-project-setup.adoc

Co-authored-by: Farzad Hayat <farzad.hayatbakhsh@tiny.cloud>

* Update modules/ROOT/partials/auth/document-converters/initial-project-setup.adoc

Co-authored-by: Farzad Hayat <farzad.hayatbakhsh@tiny.cloud>

* Update modules/ROOT/partials/auth/document-converters/initial-project-setup.adoc

* Update modules/ROOT/pages/importword-with-jwt-authentication-nodejs.adoc

* Update modules/ROOT/pages/export-to-word-with-jwt-authentication-nodejs.adoc

* Update modules/ROOT/partials/auth/document-converters/jwt-setup-document-converters.adoc

Co-authored-by: CODE:AG <57781325+abhinavgandham@users.noreply.github.com>

* DOC-2582: Minor copy edits.

---------

Co-authored-by: LewisAtTiny <lewis.hickson@tiny.cloud>
Co-authored-by: Farzad Hayat <farzad.hayatbakhsh@tiny.cloud>
Co-authored-by: CODE:AG <57781325+abhinavgandham@users.noreply.github.com>
pull/3561/head
Karl Kemister-Sheppard 8 months ago
committed by GitHub
parent
commit
ee6641638e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 9
      modules/ROOT/nav.adoc
  2. 65
      modules/ROOT/pages/export-to-pdf-with-jwt-authentication-nodejs.adoc
  3. 63
      modules/ROOT/pages/export-to-word-with-jwt-authentication-nodejs.adoc
  4. 65
      modules/ROOT/pages/importword-with-jwt-authentication-nodejs.adoc
  5. 26
      modules/ROOT/partials/auth/document-converters/configuration-steps.adoc
  6. 41
      modules/ROOT/partials/auth/document-converters/initial-project-setup.adoc
  7. 31
      modules/ROOT/partials/auth/document-converters/intro-and-prerequisites.adoc
  8. 2
      modules/ROOT/partials/auth/document-converters/jwt-setup-document-converters.adoc
  9. 44
      modules/ROOT/partials/auth/document-converters/server-setup-jwt.adoc
  10. 4
      modules/ROOT/partials/auth/private-public-key-pairs-for-tiny-cloud-services.adoc

9
modules/ROOT/nav.adoc

@ -314,17 +314,20 @@
*** xref:exportpdf.adoc[Export to PDF]
**** xref:html-to-pdf-converter-api.adoc[HTML to PDF Converter API]
**** JWT Authentication
***** xref:export-to-pdf-with-jwt-authentication-with-php.adoc[Export to PDF with JWT authentication (PHP)]
***** xref:export-to-pdf-with-jwt-authentication-nodejs.adoc[NodeJS]
***** xref:export-to-pdf-with-jwt-authentication-with-php.adoc[PHP]
*** xref:exportword.adoc[Export to Word]
**** xref:html-to-docx-converter-api.adoc[HTML to DOCX Converter API]
**** JWT Authentication
***** xref:export-to-word-with-jwt-authentication-with-php.adoc[Export to Word with JWT Authentication (PHP)]
***** xref:export-to-word-with-jwt-authentication-nodejs.adoc[NodeJS]
***** xref:export-to-word-with-jwt-authentication-with-php.adoc[PHP]
*** xref:footnotes.adoc[Footnotes]
*** xref:formatpainter.adoc[Format Painter]
*** xref:importword.adoc[Import from Word]
**** xref:docx-to-html-converter-api.adoc[DOCX to HTML Converter API]
**** JWT Authentication
***** xref:import-word-with-jwt-authentication-with-php.adoc[Import From Word with JWT Authentication (PHP)]
***** xref:importword-with-jwt-authentication-nodejs.adoc[NodeJS]
***** xref:import-word-with-jwt-authentication-with-php.adoc[PHP]
*** xref:editimage.adoc[Image Editing]
*** xref:uploadcare.adoc[Image Optimizer Powered by Uploadcare]
*** xref:inline-css.adoc[Inline CSS]

65
modules/ROOT/pages/export-to-pdf-with-jwt-authentication-nodejs.adoc

@ -0,0 +1,65 @@
= {pluginname} with JWT authentication (Node.js) Guide
:navtitle: JWT Authentication setup for Export to PDF
:description: Guide on how to setup JWT Authentication for exporting pdf files with Export to PDF
:keywords: jwt, authentication, exportpdf, pdf, node.js
:pluginname: Export to PDF
:plugincode: exportpdf
include::partial$auth/document-converters/intro-and-prerequisites.adoc[]
include::partial$auth/document-converters/initial-project-setup.adoc[]
== Setup
include::partial$auth/document-converters/jwt-setup-document-converters.adoc[leveloffset=+1]
. In the root directory, copy and paste the server setup code into the `jwt.js` file (refer to the *Configuring the Node.js Server for JWT Token Generation* section).
include::partial$auth/document-converters/server-setup-jwt.adoc[]
=== Web Page (public/index.html)
[source,html]
----
<!DOCTYPE html>
<html>
<head>
<title>TinyMCE with PDF Export</title>
<script
src="https://cdn.tiny.cloud/1/YOUR-API-KEY/tinymce/7/tinymce.min.js"
referrerpolicy="origin">
</script>
<script>
tinymce.init({
selector: 'textarea',
plugins: 'exportpdf',
toolbar: 'exportpdf',
exportpdf_converter_options: {
'format': 'Letter',
'margin_top': '1in',
'margin_right': '1in',
'margin_bottom': '1in',
'margin_left': '1in'
},
// exportpdf_token_provider fetches a token from the `/jwt` endpoint.
exportpdf_token_provider: () => {
return fetch('http://localhost:3000/jwt', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
}).then(response => response.json());
},
});
</script>
</head>
<body>
<h1>TinyMCE Export to PDF Demo</h1>
<textarea>
Welcome to TinyMCE! Try the Export to PDF feature.
</textarea>
</body>
</html>
----
include::partial$auth/document-converters/configuration-steps.adoc[]

63
modules/ROOT/pages/export-to-word-with-jwt-authentication-nodejs.adoc

@ -0,0 +1,63 @@
= {pluginname} with JWT authentication (Node.js) Guide
:navtitle: JWT Authentication setup for Export to Word
:description: Guide on how to setup JWT Authentication for exporting docx files with Export to Word
:keywords: jwt, authentication, exportword, node.js
:pluginname: Export to Word
:plugincode: exportword
include::partial$auth/document-converters/intro-and-prerequisites.adoc[]
include::partial$auth/document-converters/initial-project-setup.adoc[]
== Setup
include::partial$auth/document-converters/jwt-setup-document-converters.adoc[leveloffset=+1]
. In the root directory, copy and paste the server setup code into the `jwt.js` file (refer to the *Configuring the Node.js Server for JWT Token Generation* section).
include::partial$auth/document-converters/server-setup-jwt.adoc[]
=== Web Page (public/index.html)
[source,html]
----
<!DOCTYPE html>
<html>
<head>
<title>TinyMCE with Export to Word</title>
<script
src="https://cdn.tiny.cloud/1/YOUR-API-KEY/tinymce/7/tinymce.min.js"
referrerpolicy="origin">
</script>
<script>
tinymce.init({
selector: 'textarea',
plugins: 'exportword',
toolbar: 'exportword',
exportword_converter_options: {
'document': {
'size': 'Letter'
}
},
// exportword_token_provider fetches a token from the `/jwt` endpoint.
exportword_token_provider: () => {
return fetch('http://localhost:3000/jwt', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
}).then(response => response.json());
},
});
</script>
</head>
<body>
<h1>TinyMCE Export to Word Demo</h1>
<textarea>
Welcome to TinyMCE! Try the Export to Word feature.
</textarea>
</body>
</html>
----
include::partial$auth/document-converters/configuration-steps.adoc[]

65
modules/ROOT/pages/importword-with-jwt-authentication-nodejs.adoc

@ -0,0 +1,65 @@
= {pluginname} with JWT authentication (Node.js) Guide
:navtitle: JWT Authentication setup for Import from Word
:description: Guide on how to setup JWT Authentication for importing docx (MS Word) files with Import from Word
:keywords: jwt, authentication, importword, node.js
:pluginname: Import from Word
:plugincode: importword
include::partial$auth/document-converters/intro-and-prerequisites.adoc[]
include::partial$auth/document-converters/initial-project-setup.adoc[]
== Setup
include::partial$auth/document-converters/jwt-setup-document-converters.adoc[leveloffset=+1]
. In the root directory, copy and paste the server setup code into the `jwt.js` file (refer to the *Server Setup (jwt.js)* section).
include::partial$auth/document-converters/server-setup-jwt.adoc[]
=== Web Page (public/index.html)
[source,html]
----
<!DOCTYPE html>
<html>
<head>
<title>TinyMCE with Import from Word</title>
<script
src="https://cdn.tiny.cloud/1/YOUR-API-KEY/tinymce/7/tinymce.min.js"
referrerpolicy="origin">
</script>
<script>
tinymce.init({
selector: 'textarea',
plugins: 'importword',
toolbar: 'importword',
importword_converter_options: {
'formatting': {
'styles': 'inline',
'resets': 'inline',
'defaults': 'inline',
}
},
// importword_token_provider fetches a token from the `/jwt` endpoint.
importword_token_provider: () => {
return fetch('http://localhost:3000/jwt', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
}).then(response => response.json());
},
});
</script>
</head>
<body>
<h1>TinyMCE Import from Word Demo</h1>
<textarea>
Welcome to TinyMCE! Try the Import from Word feature.
</textarea>
</body>
</html>
----
include::partial$auth/document-converters/configuration-steps.adoc[]

26
modules/ROOT/partials/auth/document-converters/configuration-steps.adoc

@ -0,0 +1,26 @@
== Configuration Steps
=== Add Your API Key
* Replace `YOUR-API-KEY` in both files with your actual {productname} API key
* The API key should be the same in both the HTML script source and the JWT payload
=== Add Your Private Key
* Replace the private key placeholder in `jwt.js` with your actual private key
* Make sure it's in `PKCS8` format
* Keep this key secure and never share it publicly
=== Running Your Project
. Start the server:
+
[source,bash]
----
node jwt.js
----
. Open your browser to: `http://localhost:3000`
. You should see:
* The {productname} editor
* An "{pluginname}" button in the toolbar

41
modules/ROOT/partials/auth/document-converters/initial-project-setup.adoc

@ -0,0 +1,41 @@
== Quick Start Guide
=== Project Setup
[source,bash]
----
# Create and enter project directory
mkdir tinymce-my-app
cd tinymce-my-app
# Initialize project
npm init -y
# Install required packages
npm install express cors jsonwebtoken
----
Verify that the `package.json` file now includes the required dependencies.
=== Create Project Structure
[source,bash]
----
# Create the public folder for your web files
mkdir public
touch public/index.html
touch jwt.js
----
Your project should look like this:
[source]
----
/tinymce-my-app
/public
index.html (TinyMCE webpage)
jwt.js (Server code)
package.json (Project configuration)
----
. Inside the `public` folder where you created the `index.html` file add the HTML setup code (refer to the *Web Page (public/index.html)* section).

31
modules/ROOT/partials/auth/document-converters/intro-and-prerequisites.adoc

@ -0,0 +1,31 @@
== Introduction
{pluginname} requires setting up JSON Web Token (JWT) authentication to maintain control over file security. A JWT endpoint generates and provides authorization tokens that verify submitted content is sent by authorized users, preventing unauthorized access. As a standard web services authorization solution, JWT is documented extensively at link:https://jwt.io/[https://jwt.io/].
This guide provides a comprehensive walkthrough for integrating {pluginname} with {productname}, including {pluginname} functionality, by using a Node.js server for JWT token generation. It covers project setup, server configuration, and {productname} customization.
=== What You'll Build
Before diving into the technical details, here's what you'll achieve with this guide:
* A working {productname} editor running {pluginname} plugin.
* A secure authentication system using JWT token.
* A simple Node.js server to handle the authentication.
[TIP]
====
This guide is designed for developers new to JWT authentication and {productname} integration.
====
=== Prerequisites
Before starting, ensure you have:
* Node.js installed on your computer
* A {productname} API key (get one from link:https://www.tiny.cloud/signup[TinyMCE's website])
* Basic familiarity with the command line
[IMPORTANT]
====
Make sure you have your API key ready before starting. You'll need it for both the server and client configuration.
====

2
modules/ROOT/partials/auth/document-converters/jwt-setup-document-converters.adoc

@ -3,7 +3,7 @@
To set up JSON Web Token (JWT) authentication for {productname} {pluginname}:
. Add a public key to you {accountpage}, link:https://www.tiny.cloud/auth/login/[login].
. Add a public key to your {accountpage}, link:https://www.tiny.cloud/auth/login/[login].
. Set up a JSON Web Token (JWT) Provider endpoint via link:{accountjwturl}[{accountpage} - JWT Keys]
. Configure your {productname} to use the JWT endpoint.

44
modules/ROOT/partials/auth/document-converters/server-setup-jwt.adoc

@ -0,0 +1,44 @@
=== Server Setup (jwt.js)
[source,javascript]
----
const express = require('express'); // Sets up the web server.
const jwt = require('jsonwebtoken'); // Generates and signs JWTs.
const cors = require('cors'); // Allows cross-origin requests.
const path = require('path'); // Handles file paths.
const app = express();
app.use(cors());
// Your private key (Replace this with your actual key)
const privateKey = `
-----BEGIN PRIVATE KEY-----
{Your private PKCS8 key goes here}
-----END PRIVATE KEY-----
`;
app.use(express.static(path.join(__dirname, 'public')));
// JWT token generation endpoint
app.post('/jwt', (req, res) => {
const payload = {
aud: 'YOUR-API-KEY', // Replace with your actual API key
iat: Math.floor(Date.now() / 1000), // Issue timestamp
exp: Math.floor(Date.now() / 1000) + (60 * 10) // Expiration time (10 minutes)
};
try {
// Tokens are signed with the RS256 algorithm using your private key
const token = jwt.sign(payload, privateKey, { algorithm: 'RS256' });
res.json({ token });
} catch (error) {
res.status(500).send('Failed to generate JWT token.');
console.error(error.message);
}
});
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});
----

4
modules/ROOT/partials/auth/private-public-key-pairs-for-tiny-cloud-services.adoc

@ -1,4 +1,4 @@
The {pluginname} Server requires a _public_ key generated from the same _private_ key that will be used on your JSON Web Token (JWT) provider endpoint. The public key(s) stored on the {pluginname} Server are used to ensure that content is sent by authorized users.
The **{pluginname}** Server requires a _public_ key generated from the same _private_ key that will be used on your JSON Web Token (JWT) provider endpoint. The public key(s) stored on the {pluginname} Server are used to ensure that content is sent by authorized users.
There are two methods for generating and adding a public key to your API key:
@ -7,7 +7,7 @@ There are two methods for generating and adding a public key to your API key:
== Generate a key pair using the {accountpage} JWT Keys page
The link:{accountjwturl}[{accountpage} - JWT Keys] page provides a private/public key generator, providing a quick and secure way of generating the required keys. This generator will store a copy of the _public_ key, and provide a downloadable file for both the public and private keys. {companyname} does not store the _private_ key and the key pair cannot be retrieved later.
The link:{accountjwturl}[{accountpage} - JWT Keys] page provides a private/public key generator, providing a quick and secure way of generating the required keys. This generator will store a copy of the _public_ key, and provide a downloadable file for both the public and private keys. {companyname} does **not store** the _private_ key and the key pair **cannot** be retrieved later.
[[generate-a-key-pair-locally]]
== Generate a key pair locally

Loading…
Cancel
Save