Browse Source
DOC-2582: Add `exportword`, `importword` and `exportpdf` JWT authentication guides for (Node.js). (#3517)
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

committed by
GitHub

No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 344 additions and 6 deletions
-
9modules/ROOT/nav.adoc
-
65modules/ROOT/pages/export-to-pdf-with-jwt-authentication-nodejs.adoc
-
63modules/ROOT/pages/export-to-word-with-jwt-authentication-nodejs.adoc
-
65modules/ROOT/pages/importword-with-jwt-authentication-nodejs.adoc
-
26modules/ROOT/partials/auth/document-converters/configuration-steps.adoc
-
41modules/ROOT/partials/auth/document-converters/initial-project-setup.adoc
-
31modules/ROOT/partials/auth/document-converters/intro-and-prerequisites.adoc
-
2modules/ROOT/partials/auth/document-converters/jwt-setup-document-converters.adoc
-
44modules/ROOT/partials/auth/document-converters/server-setup-jwt.adoc
-
4modules/ROOT/partials/auth/private-public-key-pairs-for-tiny-cloud-services.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[] |
@ -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[] |
@ -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[] |
@ -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 |
@ -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). |
@ -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. |
|||
==== |
@ -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}`); |
|||
}); |
|||
---- |
Write
Preview
Loading…
Cancel
Save
Reference in new issue