Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 35 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
# Node.JS: Authorization Code Grant Examples
# Node.JS Launcher Code Examples

### Github repo: eg-03-node-auth-code-grant
### Github repo: [code-examples-nodejs](./)
## Introduction
This repo is a Node.JS application that demonstrates:

* Authentication with DocuSign via the
[Authorization Code Grant flow](https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-code-grant).
When the token expires, the user is asked to re-authenticate.
The **refresh token** is not used in this example.



## API version 2.1

1. **Embedded Signing Ceremony.**
[Source.](./lib/examples/eg001EmbeddedSigning.js)
This example sends an envelope, and then uses an embedded signing ceremony for the first signer.
Expand Down Expand Up @@ -82,7 +73,7 @@ The **refresh token** is not used in this example.
[Source.](./lib/examples/eg021PhoneAuthentication.js)
This example sends and envelope that requires entering in a voice-based response code for the purpose of multi-factor authentication.
1. **Requiring Knowledge-Based Authentication (KBA) for a Recipient**
[Source.](https://github.com/docusign/eg-03-node-auth-code-grant/blob/master/lib/examples/eg022KbaAuthentication.js)
[Source.](./lib/examples/eg022KbaAuthentication.js)
This example sends and envelope that requires passing a Public records check to validate identity for the purpose of multi-factor authentication.
1. **Requiring ID Verification (IDV) for a recipient**
[Source.](./lib/examples/eg023IdvAuthentication.js)
Expand Down Expand Up @@ -121,14 +112,24 @@ The **refresh token** is not used in this example.
Firstly, creates a bulk send recipients list, and then creates an envelope.
After that, initiates bulk envelope sending.



## Authentication types:

* Authentication with Docusign via [Authorization Code Grant flow](https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-code-grant) .
When the token expires, the user is asked to re-authenticate.
The **refresh token** is not used in this example.

* Authentication with DocuSign via the [JSON Web Token (JWT) Grant](https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-jsonwebtoken).
When the token expires, it updates automatically.

## Installation

### Prerequisites
1. A DocuSign Developer Sandbox account (email and password) on [demo.docusign.net](https://demo.docusign.net).
Create a [free account](https://go.docusign.com/sandbox/productshot/?elqCampaignId=16534).
1. A DocuSign Integration Key (a client ID) that is configured to use the
OAuth Authorization Code flow.
You will need the **Integration Key** itself, and its **secret**.

1. A DocuSign Integration Key (a client ID). To use Authorization code grant, you will need the **Integration Key** itself, and its **secret**. To use JSON Web token, you will need the **Integration Key** itself, the **RSA Secret Key** and an API user ID for the user you are impersonating.

If you use this example on your own workstation,
the Integration key must include a **Redirect URI** of `http://localhost:5000/ds/callback`
Expand All @@ -141,35 +142,47 @@ The **refresh token** is not used in this example.
The signer and the cc email cannot be the same.

### Installation steps
1. Download or clone this repository to your workstation to directory **eg-03-node-auth-code-grant**
1. **cd eg-03-node-auth-code-grant**
1. Download or clone this repository to your workstation to directory **code-examples-nodejs**
1. **cd code-examples-nodejs**
1. **npm install**
1. *Either:*

* Update the file **ds_configuration.js** in the project's root directory
* Update the file **config/appsettings.json** in the project's root directory
with the Integration Key
and other settings, *or*
* Create and export environment variables for the settings.
See the **ds_configuration.js** file
See the **config/appsettings.json** file
for the names of the environment variables.

**Note:** Protect your Integration Key and secret--If you update
the ds_configuration.js file, then you
the config/appsettings.json file, then you
should ensure that it will not be stored in your source code
repository.

1. **npm start**
1. Open a browser to **http://localhost:5000**

### Configuring JWT

1. Create a developer sandbox account on developers.docusign.com if you don't already have one.
2. Create a new API key in the Admin panel: https://admindemo.docusign.com/api-integrator-key, take note of the public key.
3. Set a redirect URI of `http://localhost:5000/ds/callback` as mentioned in the installation steps above for the API key you make in step 2.
4. Generate an RSA keypair in the administrator console on the DocuSign developer sandbox and copy the private key to a secure location.
5. Create a new file in your repo source folder named **private.key**, and paste in that copied RSA private key, then save it.
6. Update the file **config/appsettings.json** and include the newly created API key from step 2 as well as your account user id GUID which is also found on the Admin panel: `https://admindemo.docusign.com/api-integrator-key`.

From there you should be able to run the launcher using **npm start** then selecting **JSON Web Token** when authenticaing your account.


#### Payments code example
To use the payments example, create a
test payments gateway for your developer sandbox account.

See the
[PAYMENTS_INSTALLATION.md](./eg-03-node-auth-code-grant/blob/master/PAYMENTS_INSTALLATION.md)
[PAYMENTS_INSTALLATION.md](./code-examples-node/blob/master/PAYMENTS_INSTALLATION.md)
file for instructions.

Then add the payment gateway account id to the **ds_configuration.js** file.
Then add the payment gateway account id to the **config/appsettings.json** file.

## Using the examples with other authentication flows

Expand Down
23 changes: 23 additions & 0 deletions config/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"dsClientId": "{CLIENT_ID}",
"dsClientSecret": "{CLIENT_SECRET}",
"signerEmail": "{USER_EMAIL}",
"signerName": "{USER_FULLNAME}",
"privateKey": "{DS_PRIVATE_KEY}",
"impersonatedUserGuid": "{DS_IMPERSONATED_USER_GUID}",
"appUrl": "http://localhost:5000",
"production": false,
"debug": true,
"sessionSecret": "12345",
"allowSilentAuthentication": true,
"targetAccountId": null,
"demoDocPath": "demo_documents",
"docDocx": "World_Wide_Corp_Battle_Plan_Trafalgar.docx",
"docPdf": "World_Wide_Corp_lorem.pdf",
"gatewayAccountId": "",
"gatewayName": "stripe",
"gatewayDisplayName": "Stripe",
"githubExampleUrl": "https://github.com/docusign/code-examples-node/tree/master/lib/examples/",
"documentation": null,
"multiSourceChooser": false
}
118 changes: 118 additions & 0 deletions config/documentNames.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"node": {
"eg001": "eg001EmbeddedSigning.js",
"eg002": "eg002SigningViaEmail.js",
"eg003": "eg003ListEnvelopes.js",
"eg004": "eg004EnvelopeInfo.js",
"eg005": "eg005EnvelopeRecipients.js",
"eg006": "eg006EnvelopeDocs.js",
"eg007": "eg007EnvelopeGetDoc.js",
"eg008": "eg008CreateTemplate.js",
"eg009": "eg009UseTemplate.js",
"eg010": "eg010SendBinaryDocs.js",
"eg011": "eg011EmbeddedSending.js",
"eg012": "eg012EmbeddedConsole.js",
"eg013": "eg013AddDocToTemplate.js",
"eg014": "eg014CollectPayment.js",
"eg015": "eg015EnvelopeTabData.js",
"eg016": "eg016SetTabValues.js",
"eg017": "eg017SetTemplateTabValues.js",
"eg018": "eg018EnvelopeCustomFieldData.js",
"eg019": "eg019AccessCodeAuthentication.js",
"eg020": "eg020SmsAuthentication.js",
"eg021": "eg021PhoneAuthentication.js",
"eg022": "eg022KbaAuthentication.js",
"eg023": "eg023IdvAuthentication.js",
"eg024": "eg024CreateBrand.js",
"eg025": "eg025ApplyBrandToEnvelope.js",
"eg026": "eg026ApplyBrandToTemplate.js",
"eg027": "eg027PermissionChangeSingleSetting.js",
"eg028": "eg028CreatePermission.js",
"eg029": "eg029DeletePermission.js",
"eg030": "eg030PermissionSetUserGroup.js",
"eg031": "eg031BulkSendEnvelopes.js"
},
"java": {
"eg001": "EG001ControllerEmbeddedSigning.java",
"eg002": "EG002ControllerSigningViaEmail.java",
"eg003": "EG003ControllerListEnvelopes.java",
"eg004": "EG004ControllerEnvelopeInfo.java",
"eg005": "EG005ControllerEnvelopeRecipients.java",
"eg006": "EG006ControllerEnvelopeDocs.java",
"eg007": "EG007ControllerEnvelopeGetDoc.java",
"eg008": "EG008ControllerCreateTemplate.java",
"eg009": "EG009ControllerUseTemplate.java",
"eg010": "EG010ControllerSendBinaryDocs.java",
"eg011": "EG011ControllerEmbeddedSending.java",
"eg012": "EG012ControllerEmbeddedConsole.java",
"eg013": "EG013ControllerAddDocToTemplate.java",
"eg014": "EG014ControllerCollectPayment.java"
},
"curl": {
"eg001": "eg001EmbeddedSigning.sh",
"eg002": "eg002SigningViaEmail.sh",
"eg003": "eg003ListEnvelopes.sh",
"eg004": "eg004EnvelopeInfo.sh",
"eg005": "eg005EnvelopeRecipients.sh",
"eg006": "eg006EnvelopeDocs.sh",
"eg007": "eg007EnvelopeGetDoc.sh",
"eg008": "eg008CreateTemplate.sh",
"eg009": "eg009UseTemplate.sh",
"eg010": "eg010SendBinaryDocs.sh",
"eg011": "eg011EmbeddedSending.sh",
"eg012": "eg012EmbeddedConsole.sh",
"eg013": "eg013AddDocToTemplate.sh",
"eg014": "eg014CollectPayment.sh"
},
"php": {
"eg001": "EG001EmbeddedSigning.php",
"eg002": "EG002SigningViaEmail.php",
"eg003": "EG003ListEnvelopes.php",
"eg004": "EG004EnvelopeInfo.php",
"eg005": "EG005EnvelopeRecipients.php",
"eg006": "EG006EnvelopeDocs.php",
"eg007": "EG007EnvelopeGetDoc.php",
"eg008": "EG008CreateTemplate.php",
"eg009": "EG009UseTemplate.php",
"eg010": "EG010SendBinaryDocs.php",
"eg011": "EG011EmbeddedSending.php",
"eg012": "EG012EmbeddedConsole.php",
"eg013": "EG013AddDocToTemplate.php",
"eg015": "EG015EnvelopeTabData.php",
"eg016": "EG016SetTabValues.php",
"eg017": "EG017SetTemplateTabValues.php",
"eg018": "EG018EnvelopeCustomFieldData.php"
},
"python": {
"eg001": "eg001_embedded_signing.py",
"eg002": "eg002_signing_via_email.py",
"eg003": "eg003_list_envelopes.py",
"eg004": "eg004_envelope_info.py",
"eg005": "eg005_envelope_recipients.py",
"eg006": "eg006_envelope_docs.py",
"eg007": "eg007_envelope_get_doc.py",
"eg008": "eg008_create_template.py",
"eg009": "eg009_use_template.py",
"eg010": "eg010_send_binary_docs.py",
"eg011": "eg011_embedded_sending.py",
"eg012": "eg012_embedded_console.py",
"eg013": "eg013_add_doc_to_template.py",
"eg014": "eg014_collect_payment.py"
},
"csharp": {
"eg001": "Eg001EmbeddedSigningController.cs",
"eg002": "Eg002SigningViaEmailController.cs",
"eg003": "Eg003ListEnvelopesController.cs",
"eg004": "Eg004EnvelopeInfoController.cs",
"eg005": "Eg005EnvelopeRecipientsController.cs",
"eg006": "Eg006EnvelopeDocsController.cs",
"eg007": "Eg007EnvelopeGetDocController.cs",
"eg008": "Eg008CreateTemplateController.cs",
"eg009": "Eg009UseTemplateController.cs",
"eg010": "Eg010SendBinaryDocsController.cs",
"eg011": "Eg011EmbeddedSendingController.cs",
"eg012": "Eg012EmbeddedConsoleController.cs",
"eg013": "Eg013AddDocToTemplateController.cs",
"eg014": "Eg014CollectPaymentController.cs"
}
}
50 changes: 50 additions & 0 deletions config/documentOptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"langCode": "csharp",
"name": "C#",
"githubExampleUrl": "https://github.com/docusign/eg-03-csharp-auth-code-grant-core/tree/master/eg-03-csharp-auth-code-grant-core/Controllers/",
"owner": "docusign",
"repo": "eg-03-csharp-auth-code-grant-core",
"pathPrefix": "eg-03-csharp-auth-code-grant-core/Controllers/"
},
{
"langCode": "php",
"name": "PHP",
"githubExampleUrl": "https://github.com/docusign/eg-03-php-auth-code-grant/blob/master/src/",
"owner": "docusign",
"repo": "eg-03-php-auth-code-grant",
"pathPrefix": "src/"
},
{
"langCode": "java",
"name": "Java",
"githubExampleUrl": "https://github.com/docusign/eg-03-java-auth-code-grant/tree/master/src/main/java/com/docusign/controller/examples/",
"owner": "docusign",
"repo": "eg-03-java-auth-code-grant",
"pathPrefix": "src/main/java/com/docusign/controller/examples/"
},
{
"langCode": "node",
"name": "Node.js",
"githubExampleUrl": "https://github.com/docusign/eg-03-node-auth-code-grant/tree/master/lib/examples/",
"owner": "docusign",
"repo": "eg-03-node-auth-code-grant",
"pathPrefix": "lib/examples/"
},
{
"langCode": "curl",
"name": "API / curl",
"githubExampleUrl": "https://github.com/docusign/eg-03-curl/tree/master/examples/",
"owner": "docusign",
"repo": "eg-03-curl",
"pathPrefix": "examples/"
},
{
"langCode": "python",
"name": "Python",
"githubExampleUrl": "https://github.com/docusign/eg-03-python-auth-code-grant/tree/master/app/",
"owner": "docusign",
"repo": "eg-03-python-auth-code-grant",
"pathPrefix": "app/"
}
]
7 changes: 7 additions & 0 deletions config/github.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"UserAgent": "Example Source Updater",
"AppId": 0,
"ApiUrl": "https://api.github.com/",
"InstallationId": 0,
"PrivateKey": ""
}
22 changes: 22 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
exports.docOptions = require('./documentOptions.json');
exports.docNames = require('./documentNames.json');
const settings = require('./appsettings.json');
exports.github = require('./github.json');

const dsOauthServer = settings.production
? 'https://account.docusign.com'
: 'https://account-d.docusign.com';

settings.gatewayAccountId = process.env.DS_PAYMENT_GATEWAY_ID || settings.gatewayAccountId;
settings.dsClientSecret = process.env.DS_CLIENT_SECRET || settings.dsClientSecret;
settings.signerEmail = process.env.DS_SIGNER_EMAIL || settings.signerEmail;
settings.signerName = process.env.DS_SIGNER_NAME || settings.signerName;
settings.dsClientId = process.env.DS_CLIENT_ID || settings.dsClientId;
settings.appUrl = process.env.DS_APP_URL || settings.appUrl;
settings.privateKey = process.env.DS_PRIVATE_KEY || settings.privateKey;
settings.impersonatedUserGuid = process.env.DS_IMPERSONATED_USER_GUID || settings.impersonatedUserGuid;

exports.config = {
dsOauthServer,
...settings
};
6 changes: 3 additions & 3 deletions docs/Adding_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ All contributions must use the MIT License.
First, discuss your plans with the DevCenter Examples Manager
(Larry Kluger) via apihelp@docusign.com. He'll assign you an example number.

A new example can be added to any of the `eg-03-` series of
launchers, except for the curl repo.
A new example can be added to any of the `code-examples` series of
launchers.

After your new example has been accepted, the DevCenter team will
arrange to have it ported to the other SDK examples.
Expand Down Expand Up @@ -87,7 +87,7 @@ see lib/examples/eg002.js and its use of the example_done.ejs view.

### Configuration information
If additional configuration settings are needed, update the
`ds_configuration.js` file.
`config/appsettings.json` file.

While developing and testing, be careful not to let any of your
private information become stored in your repo.
Expand Down
Loading