Skip to content

Commit 9021f90

Browse files
authored
combined Oauth (docusign#15)
* initial commit * change from nodejs to code-examples-node * updates to readme * jwt settings + updated links * small changes to readme
1 parent 24fa985 commit 9021f90

53 files changed

Lines changed: 1112 additions & 3181 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
# Node.JS: Authorization Code Grant Examples
1+
# Node.JS Launcher Code Examples
22

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

7-
* Authentication with DocuSign via the
8-
[Authorization Code Grant flow](https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-code-grant).
9-
When the token expires, the user is asked to re-authenticate.
10-
The **refresh token** is not used in this example.
11-
12-
13-
14-
## API version 2.1
15-
167
1. **Embedded Signing Ceremony.**
178
[Source.](./lib/examples/eg001EmbeddedSigning.js)
189
This example sends an envelope, and then uses an embedded signing ceremony for the first signer.
@@ -82,7 +73,7 @@ The **refresh token** is not used in this example.
8273
[Source.](./lib/examples/eg021PhoneAuthentication.js)
8374
This example sends and envelope that requires entering in a voice-based response code for the purpose of multi-factor authentication.
8475
1. **Requiring Knowledge-Based Authentication (KBA) for a Recipient**
85-
[Source.](https://github.com/docusign/eg-03-node-auth-code-grant/blob/master/lib/examples/eg022KbaAuthentication.js)
76+
[Source.](./lib/examples/eg022KbaAuthentication.js)
8677
This example sends and envelope that requires passing a Public records check to validate identity for the purpose of multi-factor authentication.
8778
1. **Requiring ID Verification (IDV) for a recipient**
8879
[Source.](./lib/examples/eg023IdvAuthentication.js)
@@ -121,14 +112,24 @@ The **refresh token** is not used in this example.
121112
Firstly, creates a bulk send recipients list, and then creates an envelope.
122113
After that, initiates bulk envelope sending.
123114

115+
116+
117+
## Authentication types:
118+
119+
* Authentication with Docusign via [Authorization Code Grant flow](https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-code-grant) .
120+
When the token expires, the user is asked to re-authenticate.
121+
The **refresh token** is not used in this example.
122+
123+
* Authentication with DocuSign via the [JSON Web Token (JWT) Grant](https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-jsonwebtoken).
124+
When the token expires, it updates automatically.
125+
124126
## Installation
125127

126128
### Prerequisites
127129
1. A DocuSign Developer Sandbox account (email and password) on [demo.docusign.net](https://demo.docusign.net).
128130
Create a [free account](https://go.docusign.com/sandbox/productshot/?elqCampaignId=16534).
129-
1. A DocuSign Integration Key (a client ID) that is configured to use the
130-
OAuth Authorization Code flow.
131-
You will need the **Integration Key** itself, and its **secret**.
131+
132+
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.
132133

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

143144
### Installation steps
144-
1. Download or clone this repository to your workstation to directory **eg-03-node-auth-code-grant**
145-
1. **cd eg-03-node-auth-code-grant**
145+
1. Download or clone this repository to your workstation to directory **code-examples-nodejs**
146+
1. **cd code-examples-nodejs**
146147
1. **npm install**
147148
1. *Either:*
148149

149-
* Update the file **ds_configuration.js** in the project's root directory
150+
* Update the file **config/appsettings.json** in the project's root directory
150151
with the Integration Key
151152
and other settings, *or*
152153
* Create and export environment variables for the settings.
153-
See the **ds_configuration.js** file
154+
See the **config/appsettings.json** file
154155
for the names of the environment variables.
155156

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

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

165+
### Configuring JWT
166+
167+
1. Create a developer sandbox account on developers.docusign.com if you don't already have one.
168+
2. Create a new API key in the Admin panel: https://admindemo.docusign.com/api-integrator-key, take note of the public key.
169+
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.
170+
4. Generate an RSA keypair in the administrator console on the DocuSign developer sandbox and copy the private key to a secure location.
171+
5. Create a new file in your repo source folder named **private.key**, and paste in that copied RSA private key, then save it.
172+
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`.
173+
174+
From there you should be able to run the launcher using **npm start** then selecting **JSON Web Token** when authenticaing your account.
175+
176+
164177
#### Payments code example
165178
To use the payments example, create a
166179
test payments gateway for your developer sandbox account.
167180

168181
See the
169-
[PAYMENTS_INSTALLATION.md](./eg-03-node-auth-code-grant/blob/master/PAYMENTS_INSTALLATION.md)
182+
[PAYMENTS_INSTALLATION.md](./code-examples-node/blob/master/PAYMENTS_INSTALLATION.md)
170183
file for instructions.
171184

172-
Then add the payment gateway account id to the **ds_configuration.js** file.
185+
Then add the payment gateway account id to the **config/appsettings.json** file.
173186

174187
## Using the examples with other authentication flows
175188

config/appsettings.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"dsClientId": "{CLIENT_ID}",
3+
"dsClientSecret": "{CLIENT_SECRET}",
4+
"signerEmail": "{USER_EMAIL}",
5+
"signerName": "{USER_FULLNAME}",
6+
"privateKey": "{DS_PRIVATE_KEY}",
7+
"impersonatedUserGuid": "{DS_IMPERSONATED_USER_GUID}",
8+
"appUrl": "http://localhost:5000",
9+
"production": false,
10+
"debug": true,
11+
"sessionSecret": "12345",
12+
"allowSilentAuthentication": true,
13+
"targetAccountId": null,
14+
"demoDocPath": "demo_documents",
15+
"docDocx": "World_Wide_Corp_Battle_Plan_Trafalgar.docx",
16+
"docPdf": "World_Wide_Corp_lorem.pdf",
17+
"gatewayAccountId": "",
18+
"gatewayName": "stripe",
19+
"gatewayDisplayName": "Stripe",
20+
"githubExampleUrl": "https://github.com/docusign/code-examples-node/tree/master/lib/examples/",
21+
"documentation": null,
22+
"multiSourceChooser": false
23+
}

config/documentNames.json

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"node": {
3+
"eg001": "eg001EmbeddedSigning.js",
4+
"eg002": "eg002SigningViaEmail.js",
5+
"eg003": "eg003ListEnvelopes.js",
6+
"eg004": "eg004EnvelopeInfo.js",
7+
"eg005": "eg005EnvelopeRecipients.js",
8+
"eg006": "eg006EnvelopeDocs.js",
9+
"eg007": "eg007EnvelopeGetDoc.js",
10+
"eg008": "eg008CreateTemplate.js",
11+
"eg009": "eg009UseTemplate.js",
12+
"eg010": "eg010SendBinaryDocs.js",
13+
"eg011": "eg011EmbeddedSending.js",
14+
"eg012": "eg012EmbeddedConsole.js",
15+
"eg013": "eg013AddDocToTemplate.js",
16+
"eg014": "eg014CollectPayment.js",
17+
"eg015": "eg015EnvelopeTabData.js",
18+
"eg016": "eg016SetTabValues.js",
19+
"eg017": "eg017SetTemplateTabValues.js",
20+
"eg018": "eg018EnvelopeCustomFieldData.js",
21+
"eg019": "eg019AccessCodeAuthentication.js",
22+
"eg020": "eg020SmsAuthentication.js",
23+
"eg021": "eg021PhoneAuthentication.js",
24+
"eg022": "eg022KbaAuthentication.js",
25+
"eg023": "eg023IdvAuthentication.js",
26+
"eg024": "eg024CreateBrand.js",
27+
"eg025": "eg025ApplyBrandToEnvelope.js",
28+
"eg026": "eg026ApplyBrandToTemplate.js",
29+
"eg027": "eg027PermissionChangeSingleSetting.js",
30+
"eg028": "eg028CreatePermission.js",
31+
"eg029": "eg029DeletePermission.js",
32+
"eg030": "eg030PermissionSetUserGroup.js",
33+
"eg031": "eg031BulkSendEnvelopes.js"
34+
},
35+
"java": {
36+
"eg001": "EG001ControllerEmbeddedSigning.java",
37+
"eg002": "EG002ControllerSigningViaEmail.java",
38+
"eg003": "EG003ControllerListEnvelopes.java",
39+
"eg004": "EG004ControllerEnvelopeInfo.java",
40+
"eg005": "EG005ControllerEnvelopeRecipients.java",
41+
"eg006": "EG006ControllerEnvelopeDocs.java",
42+
"eg007": "EG007ControllerEnvelopeGetDoc.java",
43+
"eg008": "EG008ControllerCreateTemplate.java",
44+
"eg009": "EG009ControllerUseTemplate.java",
45+
"eg010": "EG010ControllerSendBinaryDocs.java",
46+
"eg011": "EG011ControllerEmbeddedSending.java",
47+
"eg012": "EG012ControllerEmbeddedConsole.java",
48+
"eg013": "EG013ControllerAddDocToTemplate.java",
49+
"eg014": "EG014ControllerCollectPayment.java"
50+
},
51+
"curl": {
52+
"eg001": "eg001EmbeddedSigning.sh",
53+
"eg002": "eg002SigningViaEmail.sh",
54+
"eg003": "eg003ListEnvelopes.sh",
55+
"eg004": "eg004EnvelopeInfo.sh",
56+
"eg005": "eg005EnvelopeRecipients.sh",
57+
"eg006": "eg006EnvelopeDocs.sh",
58+
"eg007": "eg007EnvelopeGetDoc.sh",
59+
"eg008": "eg008CreateTemplate.sh",
60+
"eg009": "eg009UseTemplate.sh",
61+
"eg010": "eg010SendBinaryDocs.sh",
62+
"eg011": "eg011EmbeddedSending.sh",
63+
"eg012": "eg012EmbeddedConsole.sh",
64+
"eg013": "eg013AddDocToTemplate.sh",
65+
"eg014": "eg014CollectPayment.sh"
66+
},
67+
"php": {
68+
"eg001": "EG001EmbeddedSigning.php",
69+
"eg002": "EG002SigningViaEmail.php",
70+
"eg003": "EG003ListEnvelopes.php",
71+
"eg004": "EG004EnvelopeInfo.php",
72+
"eg005": "EG005EnvelopeRecipients.php",
73+
"eg006": "EG006EnvelopeDocs.php",
74+
"eg007": "EG007EnvelopeGetDoc.php",
75+
"eg008": "EG008CreateTemplate.php",
76+
"eg009": "EG009UseTemplate.php",
77+
"eg010": "EG010SendBinaryDocs.php",
78+
"eg011": "EG011EmbeddedSending.php",
79+
"eg012": "EG012EmbeddedConsole.php",
80+
"eg013": "EG013AddDocToTemplate.php",
81+
"eg015": "EG015EnvelopeTabData.php",
82+
"eg016": "EG016SetTabValues.php",
83+
"eg017": "EG017SetTemplateTabValues.php",
84+
"eg018": "EG018EnvelopeCustomFieldData.php"
85+
},
86+
"python": {
87+
"eg001": "eg001_embedded_signing.py",
88+
"eg002": "eg002_signing_via_email.py",
89+
"eg003": "eg003_list_envelopes.py",
90+
"eg004": "eg004_envelope_info.py",
91+
"eg005": "eg005_envelope_recipients.py",
92+
"eg006": "eg006_envelope_docs.py",
93+
"eg007": "eg007_envelope_get_doc.py",
94+
"eg008": "eg008_create_template.py",
95+
"eg009": "eg009_use_template.py",
96+
"eg010": "eg010_send_binary_docs.py",
97+
"eg011": "eg011_embedded_sending.py",
98+
"eg012": "eg012_embedded_console.py",
99+
"eg013": "eg013_add_doc_to_template.py",
100+
"eg014": "eg014_collect_payment.py"
101+
},
102+
"csharp": {
103+
"eg001": "Eg001EmbeddedSigningController.cs",
104+
"eg002": "Eg002SigningViaEmailController.cs",
105+
"eg003": "Eg003ListEnvelopesController.cs",
106+
"eg004": "Eg004EnvelopeInfoController.cs",
107+
"eg005": "Eg005EnvelopeRecipientsController.cs",
108+
"eg006": "Eg006EnvelopeDocsController.cs",
109+
"eg007": "Eg007EnvelopeGetDocController.cs",
110+
"eg008": "Eg008CreateTemplateController.cs",
111+
"eg009": "Eg009UseTemplateController.cs",
112+
"eg010": "Eg010SendBinaryDocsController.cs",
113+
"eg011": "Eg011EmbeddedSendingController.cs",
114+
"eg012": "Eg012EmbeddedConsoleController.cs",
115+
"eg013": "Eg013AddDocToTemplateController.cs",
116+
"eg014": "Eg014CollectPaymentController.cs"
117+
}
118+
}

config/documentOptions.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[
2+
{
3+
"langCode": "csharp",
4+
"name": "C#",
5+
"githubExampleUrl": "https://github.com/docusign/eg-03-csharp-auth-code-grant-core/tree/master/eg-03-csharp-auth-code-grant-core/Controllers/",
6+
"owner": "docusign",
7+
"repo": "eg-03-csharp-auth-code-grant-core",
8+
"pathPrefix": "eg-03-csharp-auth-code-grant-core/Controllers/"
9+
},
10+
{
11+
"langCode": "php",
12+
"name": "PHP",
13+
"githubExampleUrl": "https://github.com/docusign/eg-03-php-auth-code-grant/blob/master/src/",
14+
"owner": "docusign",
15+
"repo": "eg-03-php-auth-code-grant",
16+
"pathPrefix": "src/"
17+
},
18+
{
19+
"langCode": "java",
20+
"name": "Java",
21+
"githubExampleUrl": "https://github.com/docusign/eg-03-java-auth-code-grant/tree/master/src/main/java/com/docusign/controller/examples/",
22+
"owner": "docusign",
23+
"repo": "eg-03-java-auth-code-grant",
24+
"pathPrefix": "src/main/java/com/docusign/controller/examples/"
25+
},
26+
{
27+
"langCode": "node",
28+
"name": "Node.js",
29+
"githubExampleUrl": "https://github.com/docusign/eg-03-node-auth-code-grant/tree/master/lib/examples/",
30+
"owner": "docusign",
31+
"repo": "eg-03-node-auth-code-grant",
32+
"pathPrefix": "lib/examples/"
33+
},
34+
{
35+
"langCode": "curl",
36+
"name": "API / curl",
37+
"githubExampleUrl": "https://github.com/docusign/eg-03-curl/tree/master/examples/",
38+
"owner": "docusign",
39+
"repo": "eg-03-curl",
40+
"pathPrefix": "examples/"
41+
},
42+
{
43+
"langCode": "python",
44+
"name": "Python",
45+
"githubExampleUrl": "https://github.com/docusign/eg-03-python-auth-code-grant/tree/master/app/",
46+
"owner": "docusign",
47+
"repo": "eg-03-python-auth-code-grant",
48+
"pathPrefix": "app/"
49+
}
50+
]

config/github.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"UserAgent": "Example Source Updater",
3+
"AppId": 0,
4+
"ApiUrl": "https://api.github.com/",
5+
"InstallationId": 0,
6+
"PrivateKey": ""
7+
}

config/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
exports.docOptions = require('./documentOptions.json');
2+
exports.docNames = require('./documentNames.json');
3+
const settings = require('./appsettings.json');
4+
exports.github = require('./github.json');
5+
6+
const dsOauthServer = settings.production
7+
? 'https://account.docusign.com'
8+
: 'https://account-d.docusign.com';
9+
10+
settings.gatewayAccountId = process.env.DS_PAYMENT_GATEWAY_ID || settings.gatewayAccountId;
11+
settings.dsClientSecret = process.env.DS_CLIENT_SECRET || settings.dsClientSecret;
12+
settings.signerEmail = process.env.DS_SIGNER_EMAIL || settings.signerEmail;
13+
settings.signerName = process.env.DS_SIGNER_NAME || settings.signerName;
14+
settings.dsClientId = process.env.DS_CLIENT_ID || settings.dsClientId;
15+
settings.appUrl = process.env.DS_APP_URL || settings.appUrl;
16+
settings.privateKey = process.env.DS_PRIVATE_KEY || settings.privateKey;
17+
settings.impersonatedUserGuid = process.env.DS_IMPERSONATED_USER_GUID || settings.impersonatedUserGuid;
18+
19+
exports.config = {
20+
dsOauthServer,
21+
...settings
22+
};

docs/Adding_examples.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ All contributions must use the MIT License.
88
First, discuss your plans with the DevCenter Examples Manager
99
(Larry Kluger) via apihelp@docusign.com. He'll assign you an example number.
1010

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

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

8888
### Configuration information
8989
If additional configuration settings are needed, update the
90-
`ds_configuration.js` file.
90+
`config/appsettings.json` file.
9191

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

0 commit comments

Comments
 (0)