Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC-2583 Add exportword, importword and exportpdf JWT authentication guides for (PHP). #3519

Merged
merged 28 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9d6a47c
Documentation for the JWT Authentication in relation to Document Expo…
lhick2108 Nov 26, 2024
e523764
DOC-2582 Removed Service URL for ExportPDF
LewisAtTiny Nov 27, 2024
9137ff8
DOC-2583 Removed Service URL for Export to Word
LewisAtTiny Nov 27, 2024
8ca221f
DOC-2583 Removed Service URL for Import Word
LewisAtTiny Nov 27, 2024
426b627
DOC-2583 Created New Folder for PHP JWT Authentication
LewisAtTiny Nov 28, 2024
4b65667
Update modules/ROOT/pages/export-to-pdf-with-jwt-authentication-with-…
LewisAtTiny Nov 28, 2024
9ce78e0
Update modules/ROOT/pages/import-word-with-jwt-authentication-with-PH…
LewisAtTiny Nov 28, 2024
9917294
Update modules/ROOT/pages/export-to-word-with-jwt-authentication-with…
LewisAtTiny Nov 28, 2024
f3600c0
Update modules/ROOT/partials/auth/document-converters/php/intro-and-p…
LewisAtTiny Nov 28, 2024
23f9b42
Update modules/ROOT/pages/import-word-with-jwt-authentication-with-PH…
LewisAtTiny Nov 28, 2024
1c852e6
Rename export-to-word-with-jwt-authentication-with-PHP.adoc to export…
LewisAtTiny Nov 28, 2024
33ffa77
DOC-2583 Rename export-to-pdf-with-jwt-authentication-with-PHP.adoc t…
LewisAtTiny Nov 28, 2024
21cc32e
DOC-2583 Rename import-word-with-jwt-authentication-with-PHP.adoc to …
LewisAtTiny Nov 28, 2024
3a6b0a7
DOC-2583 Update nav.adoc to match new page titles
LewisAtTiny Nov 28, 2024
61f91db
Update modules/ROOT/pages/export-to-pdf-with-jwt-authentication-with-…
LewisAtTiny Dec 2, 2024
679c01b
Update modules/ROOT/pages/export-to-word-with-jwt-authentication-with…
LewisAtTiny Dec 2, 2024
c9a4f61
Update modules/ROOT/pages/import-word-with-jwt-authentication-with-ph…
LewisAtTiny Dec 2, 2024
553bdf5
Update modules/ROOT/partials/auth/document-converters/php/initial-pro…
LewisAtTiny Dec 3, 2024
0806c98
Update modules/ROOT/partials/private-public-key-pairs-for-tiny-cloud-…
LewisAtTiny Dec 3, 2024
5b5bfe9
Update modules/ROOT/partials/private-public-key-pairs-for-tiny-cloud-…
LewisAtTiny Dec 3, 2024
e30162f
Update modules/ROOT/partials/private-public-key-pairs-for-tiny-cloud-…
LewisAtTiny Dec 3, 2024
54f9d44
Update modules/ROOT/pages/export-to-pdf-with-jwt-authentication-with-…
LewisAtTiny Dec 3, 2024
9010dc1
Update modules/ROOT/pages/export-to-word-with-jwt-authentication-with…
LewisAtTiny Dec 3, 2024
aabd35f
Update modules/ROOT/pages/import-word-with-jwt-authentication-with-ph…
LewisAtTiny Dec 3, 2024
8c9daab
Update modules/ROOT/partials/auth/document-converters/php/initial-pro…
LewisAtTiny Dec 9, 2024
c449ddb
DOC-2583: Farzad/Lewis structural improvements
FarzadHayat Dec 9, 2024
26c5e1e
DOC-2583: Farzad/Lewis fix import/export docx nav structure
FarzadHayat Dec 10, 2024
18186c4
Update modules/ROOT/partials/auth/document-converters/php/initial-pro…
LewisAtTiny Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,18 @@
*** xref:advtable.adoc[Enhanced Tables]
*** 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: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: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:editimage.adoc[Image Editing]
*** xref:inline-css.adoc[Inline CSS]
*** xref:linkchecker.adoc[Link Checker]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
= {pluginname} with JWT authentication (PHP) Guide
:navtitle: JWT Authentication setup for Export to PDF
:description: Guide on how to setup JWT Authentication for exporting PDF files with {productname}
:keywords: jwt, authentication, exportpdf, pdf, php
:pluginname: Export to PDF
:plugincode: exportpdf

include::partial$auth/document-converters/php/intro-and-prerequisites.adoc[]

include::partial$auth/document-converters/php/initial-project-setup.adoc[]

== Setup

=== Generate a Public/Private Key Pair

include::partial$auth/document-converters/jwt-setup-document-converters.adoc[leveloffset=+2]

include::partial$auth/document-converters/php/server-setup-php.adoc[]

=== Web Page Setup (index.html)

Inside the `public` folder where you created the `index.html` file add the HTML setup code:

[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.php` endpoint.
exportpdf_token_provider: () => {
return fetch('http://localhost:3000/jwt.php', {
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/php/configuration-steps.adoc[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
= {pluginname} with JWT authentication (PHP) Guide
:navtitle: JWT Authentication setup for Export to Word
:description: Guide on how to setup JWT Authentication for exporting Word files with {productname}
:keywords: jwt, authentication, exportword, word, php
:pluginname: Export to Word
:plugincode: exportword

include::partial$auth/document-converters/php/intro-and-prerequisites.adoc[]

include::partial$auth/document-converters/php/initial-project-setup.adoc[]

== Setup

=== Generate a Public/Private Key Pair

include::partial$auth/document-converters/jwt-setup-document-converters.adoc[leveloffset=+2]

include::partial$auth/document-converters/php/server-setup-php.adoc[]

=== Web Page Setup (index.html)

Inside the `public` folder where you created the `index.html` file add the HTML setup code:

[source,html]
----
<!DOCTYPE html>
<html>
<head>
<title>TinyMCE with Word 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: 'exportword',
toolbar: 'exportword',
exportword_converter_options: {
'format': 'Letter',
'margin_top': '1in',
'margin_right': '1in',
'margin_bottom': '1in',
'margin_left': '1in'
},
// exportword_token_provider fetches a token from the `/jwt.php` endpoint.
exportword_token_provider: () => {
return fetch('http://localhost:3000/jwt.php', {
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/php/configuration-steps.adoc[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
= {pluginname} with JWT authentication (PHP) Guide
:navtitle: JWT Authentication setup for Import from Word
:description: Guide on how to setup JWT Authentication for importing Word files with {productname}
:keywords: jwt, authentication, importword, word, php
:pluginname: Import from Word
:plugincode: importword

include::partial$auth/document-converters/php/intro-and-prerequisites.adoc[]

include::partial$auth/document-converters/php/initial-project-setup.adoc[]

== Setup

=== Generate a Public/Private Key Pair

include::partial$auth/document-converters/jwt-setup-document-converters.adoc[leveloffset=+2]

include::partial$auth/document-converters/php/server-setup-php.adoc[]

=== Web Page Setup (index.html)

Inside the `public` folder where you created the `index.html` file add the HTML setup code:

[source,html]
----
<!DOCTYPE html>
<html>
<head>
<title>TinyMCE with Word Import</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: {
'format': 'Letter',
'margin_top': '1in',
'margin_right': '1in',
'margin_bottom': '1in',
'margin_left': '1in'
},
// importword_token_provider fetches a token from the `/jwt.php` endpoint.
importword_token_provider: () => {
return fetch('http://localhost:3000/jwt.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
}).then(response => response.json());
},
});
</script>
</head>
<body>
<h1>TinyMCE Import Word Demo</h1>
<textarea>
Welcome to TinyMCE! Try the Import from Word feature.
</textarea>
</body>
</html>
----

include::partial$auth/document-converters/php/configuration-steps.adoc[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[[setting-up-jwt-authentication]]
== Setting up JWT authentication

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].
. Set up a JSON Web Token (JWT) Provider endpoint via link:{accountjwturl}[{accountpage} - JWT Keys]
. Configure your {productname} to use the JWT endpoint.

include::partial$auth/private-public-key-pairs-for-tiny-cloud-services.adoc[]

[[set-up-a-json-web-token-jwt-endpoint]]
== Set up a JSON Web Token (JWT) endpoint

include::partial$auth/how-jwts-are-used.adoc[]

=== JWT endpoint requirements

A JSON Web Token (JWT) endpoint for {pluginname} requires:

* The endpoint or server accepts a JSON HTTP POST request.
* User authentication - A method of verifying the user, and that they should have access to the {pluginname}.
* The JWTs are generated (signed) using the _private_ key that pairs with the _public_ key provided to link:{accountjwturl}[{accountpage} - JWT Keys].
* The endpoint or server produces a JSON response with the token. {pluginname} will submit the token with requests to the {pluginname} Server.

=== Required JWT claims for {pluginname}

JSON Web Tokens produced by the JWT endpoint must include the following claims:

`+aud+` _(required)_::
*Type:* `+String+`
+
The `aud` is case-sensitive string that must match a valid API key that has the {pluginname} plugin enabled.

`+iat+` _(required)_::
*Type:* `+Number+`
+
The `iat` represents the issue timestamp, specified as the number of seconds. For example, to set the issue time to the current timestamp, calculate the issue time as the current timestamp divided by 1000.

.Example
[source,json]
----
iat: Math.floor(Date.now() / 1000), // Issue timestamp
----

`+exp+` _(required)_::
*Type:* `+Number+`
+
The `exp` represents the expiration timestamp, specified as the number of seconds. For example, to set a validity period of 10 minutes, calculate the expiration time as the current timestamp plus 600 seconds.

.Example
[source,json]
----
exp: Math.floor(Date.now() / 1000) + (60 * 10) // Expiration time (10 minutes)
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=== Configuration Steps

==== 1. 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

==== 2. Add Your Private Key

* Replace the private key placeholder in `jwt.php` 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]
----
php -S localhost:3000
----

. Open your browser to: `http://localhost:3000`
. You should see:
* The {productname} editor
* An "{pluginname}" button in the toolbar
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
== Update PHP Configuration File

Use the following command to locate the PHP configuration file:

[source,bash]
----
php --ini
----

Open the configuration file in a text editor and ensure the following settings are enabled:

[source,ini]
----
extension=openssl
extension_dir='ext'
----

[TIP]
The path to the extension directory may vary depending on your system.
LewisAtTiny marked this conversation as resolved.
Show resolved Hide resolved

== Quick Start Guide

=== Project Setup

[source,bash]
----
# Create and enter project directory
mkdir tinymce-app
cd tinymce-app
# Initialize Composer
composer require firebase/php-jwt
----

=== Create Project Structure

[source,bash]
----
# Create the public folder for your web files
touch index.html
touch jwt.php
----

Your project should look like this:

[source]
----
/tinymce-app
index.html (TinyMCE webpage)
jwt.php (Server code)
composer.json
composer.lock
vendor
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
== 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 PHP 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 tokens
* A simple PHP 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:

* PHP installed on your computer (to check, run `php -v` in your terminal)
* OpenSSL installed on your computer (to check, run `openssl version` in your terminal)
* Composer installed on your computer (to check, run `composer -v` in your terminal)
* 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.
====
Loading
Loading