XOAuth2 for Email-In node (#975)

* Update PULL_REQUEST_TEMPLATE.md

* Add new UI elements to Email In node

Locale for en-US
Added Auth type and Token field to Email IN
Dynamically appear based on selection

* XOAUTH2 IMAP

Minor UI changes. Exposing only XOAuth2. Picks up raw access token from input message specified.

Only works for IMAP
Token formatted by node for Exchange and GMail, won't work on other providers.
Only works on trigger, not timer

TODO:
Add POP XOAUTH2 capability
Add SMTP XOAUTH2 capability
Add option to pass SASL XAOUTH2 token rather than raw OAUTH2 token

* SASL Format

Added checkbox to turn off SASL formatting if the user wants to do this themselves

* XOAuth2 forces input

Using XOauth2 forces triggered node, and automatic trigger sets auth to basic;
XOAuth2 needs token from flow

* Error reporting

Password missing error only occurs if set to basic authentication.

Token missing only occurs if set to XOAuth2.

* Unit tests

Make sure basic authentication is selected by default, and that an additional input is created and timed triggers are turned off for XOauth2

* Cleanup and README

Remove old code, update readme

* XOauth2 IMAP Release

Prevent XOAuth2 being used for POP. Update PR Template.
Updated help file.
Bumped version to 1.19-beta

* Update POP3 dependency

Removed dependency to poplib.js, moved to node-pop3. Re-wrote checkPOP3 function asynchronously using the new library. Added some node.status changes to mimic IMAP behaviour.

* XOAUTH2 POP3

Added checking for authentication type to allow XOauth2 tokens to be sent to POP server. Turned off UI restrictions for this functionality.

* XOAUTH2 POP3 Release

Updated help docs and version to reflect changes.

* Add new UI elements to Email Out node

Add option for XAouth2 for SMTP node

* XOAUTH2 SMTP

Exposing functionality for OAuth2 through Nodemailer. Added some error reporting if credentials are missing to match the Email-In node.

* XOAUTH2 SMTP Release

Updated help file to reflect changes.

* Unit Tests for Email Out

Modified tests to allow these unit tests to pass, but does not address the fault caused by the Node Test Helper - credentials only loaded after the flow has been loaded.

---------

Co-authored-by: Dave Conway-Jones <dceejay@users.noreply.github.com>
This commit is contained in:
wooferguy
2023-03-28 08:27:47 +13:00
committed by GitHub
parent 497270ba74
commit 9a57958a1e
10 changed files with 383 additions and 1031 deletions

View File

@@ -8,6 +8,16 @@
default value.</p>
<h3>Gmail users</h3>
<p>If you are accessing Gmail you may need to either enable <a target="_new" href="https://support.google.com/mail/answer/185833?hl=en">an application password</a>.</p>
<h3>Authentication</h3>
<p>When connecting to a SMTP server, two authentication types are available: Basic and XOAuth2.</p>
<ul>
<li><b>Basic:</b> requires a username and password to be entered</li>
<li><b>XOAuth2:</b> requires a username and a <code>msg</code> property to extract the access token</li>
</ul>
<h3>SASL Formatting:</h3>
<p>SASL XOAuth2 tokens are created by combining the username and token, encoding it in base64, and passing it to the mail server in the following format:</p>
<pre>base64("user=" + userName + "^Aauth=Bearer " + accessToken + "^A^A")</pre>
<p>If the checkbox is unticked, flow creators can format the token themselves before passing it to the node.</p>
<h3>Details</h3>
<p>The payload can be html format. You may supply a separate plaintext version using <code>msg.plaintext</code>.
If you don't and <code>msg.payload</code> contains html, it will also be used for the plaintext.
@@ -25,33 +35,59 @@
</script>
<script type="text/html" data-help-name="e-mail in">
<p>Repeatedly gets emails from a POP3 or IMAP server and forwards on as a msg if not already seen.</p>
<p>The subject is loaded into <code>msg.topic</code> and <code>msg.payload</code> is the plain text body.
If there is text/html then that is returned in <code>msg.html</code>. <code>msg.from</code> and <code>msg.date</code> are also set if you need them.</p>
<p>Additionally <code>msg.header</code> contains the complete header object including
<i>to</i>, <i>cc</i> and other potentially useful properties.</p>
<p>It can optionally mark the message as Read (default), Delete it, or leave unmarked (None).</p>
<p>Uses the <a href="https://github.com/mscdex/node-imap/blob/master/README.md" target="_new">node-imap module</a> - see that page for
information on the <code>msg.criteria</code> format if needed.</p>
<p>Any attachments supplied in the incoming email can be found in the <code>msg.attachments</code> property. This will be an array of objects where
each object represents a specific attachments. The format of the object is:</p>
<pre>
{
contentType: // The MIME content description
fileName: // A suggested file name associated with this attachment
transferEncoding: // How was the original email attachment encodded?
contentDisposition: // Unknown
generatedFileName: // A suggested file name associated with this attachment
contentId: // A unique generated ID for this attachment
checksum: // A checksum against the data
length: // Size of data in bytes
content: // The actual content of the data contained in a Node.js Buffer object
// We can turn this into a base64 data string with content.toString('base64')
}
</pre>
<p><b>Note</b>: For POP3, the default port numbers are 110 for plain TCP and 995 for SSL. For IMAP the port numbers are 143 for plain TCP and 993 for SSL.</p>
<p><b>Note</b>: With option 'STARTTLS' an established plain connection is upgraded to an encrypted one. Set to 'always' to always attempt connection upgrades via STARTTLS, 'required' only if upgrading is required, or 'never' to never attempt upgrading.</p>
<p><b>Note</b>: The maximum refresh interval is 2147483 seconds (24.8 days).</p>
<h3>Overview</h3>
<p>The e-mail in node retrieves emails from a POP3 or IMAP server and forwards the email data as a message if it has not already been seen.</p>
<h3>Message Properties</h3>
<p>The following properties are set on the message object:</p>
<ul>
<li><code>msg.topic</code> - the subject of the email</li>
<li><code>msg.payload</code> - the plain text body of the email</li>
<li><code>msg.html</code> - the HTML body of the email (if present)</li>
<li><code>msg.from</code> - the sender of the email</li>
<li><code>msg.date</code> - the date the email was sent</li>
<li><code>msg.header</code> - the complete header object including information such as the "to" and "cc" recipients</li>
<li><code>msg.attachments</code> - an array of objects representing any attachments included in the email</li>
</ul>
<h3>Module Used</h3>
<p>The e-mail in node uses the <a href="https://github.com/mscdex/node-imap/blob/master/README.md" target="_new">node-imap module</a>, see that page for information on the <code>msg.criteria</code> format if needed.</p>
<p>It also makes use of <a href="https://github.com/node-pop3/node-pop3#readme" target="_new">node-pop3 module</a></p>
<h3>Attachment Format</h3>
<p>Each object in the <code>msg.attachments</code> array is formatted as follows:</p>
<pre>
{
contentType: // The MIME content description
fileName: // A suggested file name associated with this attachment
transferEncoding: // How was the original email attachment encoded?
contentDisposition: // Unknown
generatedFileName: // A suggested file name associated with this attachment
contentId: // A unique generated ID for this attachment
checksum: // A checksum against the data
length: // Size of data in bytes
content: // The actual content of the data contained in a Node.js Buffer object
// We can turn this into a base64 data string with content.toString('base64')
}
</pre>
<h3>Authentication</h3>
<p>When connecting to a POP3 or IMAP server, two authentication types are available: Basic and XOAuth2.</p>
<ul>
<li><b>Basic:</b> requires a username and password to be entered</li>
<li><b>XOAuth2:</b> requires a username and a <code>msg</code> property to extract the access token</li>
</ul>
<p>With XOAuth2 authentication, periodic fetching is not available. The node will only attemp to login when a new token is receieved.</p>
<h3>SASL Formatting:</h3>
<p>SASL XOAuth2 tokens are created by combining the username and token, encoding it in base64, and passing it to the mail server in the following format:</p>
<pre>base64("user=" + userName + "^Aauth=Bearer " + accessToken + "^A^A")</pre>
<p>If the checkbox is unticked, flow creators can format the token themselves before passing it to the node.</p>
<h3>Notes</h3>
<ul>
<li>For POP3, the default port numbers are 110 for plain TCP and 995 for SSL. For IMAP the port numbers are 143 for plain TCP and 993 for SSL.</li>
<li>With option 'STARTTLS' an established plain connection is upgraded to an encrypted one. Set to 'always' to always attempt connection upgrades via STARTTLS, 'required' only if upgrading is required, or 'never' to never attempt upgrading.</li>
<li>The maximum refresh interval is 2147483 seconds (24.8 days).</li>
</ul>
</script>