Skip to content

Commit 9d6a47c

Browse files
committed
Documentation for the JWT Authentication in relation to Document Exporters and Importers
1 parent fe5942f commit 9d6a47c

8 files changed

+345
-0
lines changed

modules/ROOT/nav.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,15 @@
313313
*** xref:advtable.adoc[Enhanced Tables]
314314
*** xref:exportpdf.adoc[Export to PDF]
315315
**** xref:html-to-pdf-converter-api.adoc[HTML to PDF Converter API]
316+
**** xref:export-to-pdf-with-jwt-authentication-with-PHP.adoc[Export to PDF with JWT authentication (PHP)]
316317
*** xref:exportword.adoc[Export to Word]
317318
**** xref:html-to-docx-converter-api.adoc[HTML to DOCX Converter API]
319+
**** xref:export-to-word-with-jwt-authentication-with-PHP.adoc[Export to Word with JWT Authentication (PHP)]
318320
*** xref:footnotes.adoc[Footnotes]
319321
*** xref:formatpainter.adoc[Format Painter]
320322
*** xref:importword.adoc[Import from Word]
321323
**** xref:docx-to-html-converter-api.adoc[DOCX to HTML Converter API]
324+
**** xref:import-word-with-jwt-authentication-with-PHP.adoc[Import From Word with JWT Authentication (PHP)]
322325
*** xref:editimage.adoc[Image Editing]
323326
*** xref:inline-css.adoc[Inline CSS]
324327
*** xref:linkchecker.adoc[Link Checker]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
= Export to PDF with JWT authentication (PHP) Guide
2+
:navtitle: JWT Authentication setup for Export to PDF
3+
:description: Guide on how to setup JWT Authentication for exporting PDF files with {productname}
4+
:keywords: jwt, authentication, exportpdf, pdf, php
5+
:pluginname: Export to PDF
6+
:plugincode: exportpdf
7+
8+
include::partial$auth/document-converters/php/intro-and-prerequisites.adoc[]
9+
10+
include::partial$auth/document-converters/php/initial-project-setup.adoc[]
11+
12+
. Inside the `public` folder where you created the `index.html` file add the HTML setup code (refer to the *Setting up {productname} HTML* section).
13+
14+
==== Web Page Setup (index.html)
15+
16+
[source,html]
17+
----
18+
<!DOCTYPE html>
19+
<html>
20+
<head>
21+
<title>TinyMCE with PDF Export</title>
22+
<script
23+
src="https://cdn.tiny.cloud/1/YOUR-API-KEY/tinymce/7/tinymce.min.js"
24+
referrerpolicy="origin">
25+
</script>
26+
<script>
27+
tinymce.init({
28+
selector: 'textarea',
29+
plugins: 'exportpdf',
30+
toolbar: 'exportpdf',
31+
exportpdf_converter_options: {
32+
'format': 'Letter',
33+
'margin_top': '1in',
34+
'margin_right': '1in',
35+
'margin_bottom': '1in',
36+
'margin_left': '1in'
37+
},
38+
exportpdf_service_url: "<serviceURL>",
39+
// export_token_provider fetches a token from the `/jwt.php` endpoint.
40+
exportpdf_token_provider: () => {
41+
return fetch('http://localhost:3000/jwt.php', {
42+
method: 'POST',
43+
headers: { 'Content-Type': 'application/json' },
44+
}).then(response => response.json());
45+
},
46+
});
47+
</script>
48+
</head>
49+
<body>
50+
<h1>TinyMCE Export to PDF Demo</h1>
51+
<textarea>
52+
Welcome to TinyMCE! Try the Export to PDF feature.
53+
</textarea>
54+
</body>
55+
</html>
56+
----
57+
58+
. In the root directory, copy and paste the server setup code into the `jwt.php` file.
59+
60+
include::partial$auth/document-converters/php/server-setup-php.adoc[]
61+
62+
include::partial$auth/document-converters/php/configuration-steps.adoc[]
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
= Export to Word with JWT authentication (PHP) Guide
2+
:navtitle: JWT Authentication setup for Export to Word
3+
:description: Guide on how to setup JWT Authentication for exporting Word files with {productname}
4+
:keywords: jwt, authentication, exportword, word, php
5+
:pluginname: Export to Word
6+
:plugincode: exportword
7+
8+
include::partial$auth/document-converters/php/intro-and-prerequisites.adoc[]
9+
10+
include::partial$auth/document-converters/php/initial-project-setup.adoc[]
11+
12+
13+
. Inside the `public` folder where you created the `index.html` file add the HTML setup code (refer to the *Setting up {productname} HTML* section).
14+
15+
==== Web Page Setup (index.html)
16+
17+
[source,html]
18+
----
19+
<!DOCTYPE html>
20+
<html>
21+
<head>
22+
<title>TinyMCE with Word Export</title>
23+
<script
24+
src="https://cdn.tiny.cloud/1/YOUR-API-KEY/tinymce/7/tinymce.min.js"
25+
referrerpolicy="origin">
26+
</script>
27+
<script>
28+
tinymce.init({
29+
selector: 'textarea',
30+
plugins: 'exportword',
31+
toolbar: 'exportword',
32+
exportword_converter_options: {
33+
'format': 'Letter',
34+
'margin_top': '1in',
35+
'margin_right': '1in',
36+
'margin_bottom': '1in',
37+
'margin_left': '1in'
38+
},
39+
exportword_service_url: "<serviceURL>",
40+
// export_token_provider fetches a token from the `/jwt.php` endpoint.
41+
exportword_token_provider: () => {
42+
return fetch('http://localhost:3000/jwt.php', {
43+
method: 'POST',
44+
headers: { 'Content-Type': 'application/json' },
45+
}).then(response => response.json());
46+
},
47+
});
48+
</script>
49+
</head>
50+
<body>
51+
<h1>TinyMCE Export to Word Demo</h1>
52+
<textarea>
53+
Welcome to TinyMCE! Try the Export to Word feature.
54+
</textarea>
55+
</body>
56+
</html>
57+
----
58+
59+
. In the root directory, copy and paste the server setup code into the `jwt.php` file.
60+
61+
include::partial$auth/document-converters/php/server-setup-php.adoc[]
62+
63+
include::partial$auth/document-converters/php/configuration-steps.adoc[]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
= Import Word to TinyMCE Editor with JWT authentication (PHP) Guide
2+
:navtitle: JWT Authentication setup for Import Word to TinyMCE Edtior
3+
:description: Guide on how to setup JWT Authentication for importing Word files with {productname}
4+
:keywords: jwt, authentication, importword, word, php
5+
:pluginname: Import from Word
6+
:plugincode: importword
7+
8+
include::partial$auth/document-converters/php/intro-and-prerequisites.adoc[]
9+
10+
include::partial$auth/document-converters/php/initial-project-setup.adoc[]
11+
12+
. Inside the `public` folder where you created the `index.html` file add the HTML setup code (refer to the *Setting up {productname} HTML* section).
13+
14+
==== Web Page Setup (index.html)
15+
16+
[source,html]
17+
----
18+
<!DOCTYPE html>
19+
<html>
20+
<head>
21+
<title>TinyMCE with Word Import</title>
22+
<script
23+
src="https://cdn.tiny.cloud/1/YOUR-API-KEY/tinymce/7/tinymce.min.js"
24+
referrerpolicy="origin">
25+
</script>
26+
<script>
27+
tinymce.init({
28+
selector: 'textarea',
29+
plugins: 'importword',
30+
toolbar: 'importword',
31+
importword_converter_options: {
32+
'format': 'Letter',
33+
'margin_top': '1in',
34+
'margin_right': '1in',
35+
'margin_bottom': '1in',
36+
'margin_left': '1in'
37+
},
38+
importword_service_url: "<serviceURL>",
39+
// import_token_provider fetches a token from the `/jwt.php` endpoint.
40+
importword_token_provider: () => {
41+
return fetch('http://localhost:3000/jwt.php', {
42+
method: 'POST',
43+
headers: { 'Content-Type': 'application/json' },
44+
}).then(response => response.json());
45+
},
46+
});
47+
</script>
48+
</head>
49+
<body>
50+
<h1>TinyMCE Import Word Demo</h1>
51+
<textarea>
52+
Welcome to TinyMCE! Try the Import from Word feature.
53+
</textarea>
54+
</body>
55+
</html>
56+
----
57+
58+
. In the root directory, copy and paste the server setup code into the `jwt.php` file.
59+
60+
include::partial$auth/document-converters/php/server-setup-php.adoc[]
61+
62+
include::partial$auth/document-converters/php/configuration-steps.adoc[]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== Configuration Steps
2+
3+
==== 1. Add Your API Key
4+
5+
* Replace `YOUR-API-KEY` in both files with your actual {productname} API key
6+
* The API key should be the same in both the HTML script source and the JWT payload
7+
8+
==== 2. Add Your Private Key
9+
10+
* Replace the private key placeholder in `jwt.php` with your actual private key
11+
* Make sure it's in `PKCS8` format
12+
* Keep this key secure and never share it publicly
13+
14+
=== Running Your Project
15+
16+
. Start the server:
17+
+
18+
[source,bash]
19+
----
20+
php -S localhost:3000
21+
----
22+
23+
. Open your browser to: `http://localhost:3000`
24+
. You should see:
25+
* The {productname} editor
26+
* An "{pluginname}" button in the toolbar
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
== Update PHP php.ini Files
2+
3+
Update files inside the downloaded php package:
4+
5+
* php.ini
6+
* php.ini-development
7+
* php.ini-production
8+
9+
Ensure the following lines are uncommented:
10+
11+
[source, bash]
12+
----
13+
extension=openssl
14+
extension_dir={Depends on your development environment}
15+
----
16+
17+
== Quick Start Guide
18+
19+
=== Project Setup (5 minutes)
20+
21+
[source,bash]
22+
----
23+
# Create and enter project directory
24+
mkdir tinymce-app
25+
cd tinymce-app
26+
# Initialize Composer
27+
composer require firebase/php-jwt
28+
----
29+
30+
=== Create Project Structure
31+
32+
[source,bash]
33+
----
34+
# Create the public folder for your web files
35+
touch index.html
36+
touch jwt.php
37+
----
38+
39+
Your project should look like this:
40+
41+
[source]
42+
----
43+
/tinymce-app
44+
index.html (TinyMCE webpage)
45+
jwt.php (Server code)
46+
composer
47+
composer.lock
48+
vendor
49+
----
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
== Introduction
2+
3+
{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/].
4+
5+
This guide provides a comprehensive walkthrough for integrating {pluginname} with {productname}, including {pluginname} functionality, by using a PHP server for JWT token generation. It covers project setup, server configuration, and {productname} customization.
6+
7+
== What You'll Build
8+
9+
Before diving into the technical details, here's what you'll achieve with this guide:
10+
11+
* A working {productname} editor running {pluginname} plugin.
12+
* A secure authentication system using JWT tokens
13+
* A simple PHP server to handle the authentication
14+
15+
[TIP]
16+
====
17+
This guide is designed for developers new to JWT authentication and {productname} integration.
18+
====
19+
20+
=== Prerequisites
21+
22+
Before starting, ensure you have:
23+
24+
* PHP installed on your computer
25+
* OpenSSL is installed on your computer
26+
* Composer is installed on your computer
27+
* A {productname} API key (get one from link:https://www.tiny.cloud/signup[TinyMCE's website])
28+
* Basic familiarity with the command line
29+
30+
[IMPORTANT]
31+
====
32+
Make sure you have your API key ready before starting. You'll need it for both the server and client configuration.
33+
====
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
==== Server Setup (jwt.php)
2+
3+
[source,php]
4+
----
5+
<?php
6+
require 'vendor/autoload.php'; // Setting up the Autoload
7+
use \Firebase\JWT\JWT;
8+
9+
function fatalError($message) {
10+
http_response_code(500);
11+
header('Content-Type: application/json');
12+
die(json_encode(array("message" => "JWT auth failed: " . $message)));
13+
}
14+
15+
// Check for OpenSSL extension
16+
if (!extension_loaded('openssl')) {
17+
fatalError('You need to enable the openssl extension in your php.ini.');
18+
}
19+
20+
// Enable CORS
21+
header("Access-Control-Allow-Origin: *");
22+
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
23+
24+
// JWT payload
25+
$payload = array(
26+
"aud" => "YOUR-API-KEY-HERE",
27+
"iat" => time(), // Issue timestamp
28+
"exp" => time() + 60 * 10 // Expiration time (10 minutes)
29+
);
30+
31+
try {
32+
// Tokens are signed with the RS256 algorithm your private key
33+
$privateKey = <<<EOD
34+
-----BEGIN PRIVATE KEY-----
35+
{Your private PKCS8 key goes here}
36+
-----END PRIVATE KEY-----
37+
EOD;
38+
$token = JWT::encode($payload, $privateKey, 'RS256');
39+
40+
http_response_code(200);
41+
header('Content-Type: application/json');
42+
echo json_encode(array("token" => $token));
43+
} catch (Exception $e) {
44+
fatalError($e->getMessage());
45+
}
46+
?>
47+
----

0 commit comments

Comments
 (0)