Skip to content

Commit 21002ca

Browse files
committed
2 parents 55f91d3 + ce384b1 commit 21002ca

File tree

4 files changed

+47
-30
lines changed

4 files changed

+47
-30
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
app/ds_config*
2+
13
*/.DS_Store
24
.DS_Store
35
.idea/*

README.md

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
# Python: Authorization Code Grant Examples
1+
# Python Launcher Code Examples
22

3-
### Github repo: eg-03-python-auth-code-grant
3+
### Github repo: [code-examples-python](./)
44
## Introduction
55
This repo is a Python 3 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-
* Authentication with DocuSign via the [JSON Web Token (JWT) Grant](https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-jsonwebtoken).
12-
When the token expires, it updates automatically.
7+
138
1. **Embedded Signing Ceremony.**
149
[Source.](./app/examples/eg001_embedded_signing/controller.py)
1510
This example sends an envelope, and then uses an embedded signing ceremony for the first signer.
@@ -119,14 +114,23 @@ When the token expires, it updates automatically.
119114
Firstly, creates a bulk send recipients list, and then creates an envelope.
120115
After that, initiates bulk envelope sending.
121116

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

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

131135
If you use this example on your own workstation,
132136
the Integration key must include a **Redirect URI** of `http://localhost:5000/ds/callback`
@@ -147,16 +151,28 @@ When the token expires, it updates automatically.
147151
1. Download or clone this repository to your workstation to directory **eg-03-python-auth-code-grant**
148152
1. **cd eg-03-python-auth-code-grant**
149153
1. **pip3 install -r requirements.txt** (or pipenv can be used)
150-
1. Update the file **app/ds_config.py**
151-
with the Integration Key and other settings.
154+
1. Make a copy of the **app/ds_config_sample.py** and name it **ds_config.py**
155+
1. Update this new file **app/ds_config.py**
156+
with your Integration Key and other settings.
152157

153158
**Note:** Protect your Integration Key and secret--you
154159
should ensure that ds_config.py file will not be stored in your source code
155160
repository.
156161

157-
1. **python3 run.py**
162+
1. **python run.py**
158163
1. Open a browser to **http://localhost:5000**
159164

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 **app/ds_config.py** 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 **python run.py** then selecting **JSON Web Token** when authenticaing your account.
175+
160176
#### Payments code example
161177
To use the payments example, create a
162178
test payments gateway for your developer sandbox account.
@@ -167,18 +183,20 @@ file for instructions.
167183

168184
Then add the payment gateway account id to the **app/ds_config.py** file.
169185

170-
## Using the examples with other authentication flows
171186

172-
The examples in this repository can also be used with either the
173-
Implicit Grant or JWT OAuth flows.
174-
See the [Authentication guide](https://developers.docusign.com/esign-rest-api/guides/authentication)
175-
for information on choosing the right authentication flow for your application.
176187

177188
## License and additional information
178189

190+
### Implicit Grant
191+
192+
The examples in this repository can also be used with the
193+
Implicit Grant OAuth flow.
194+
See the [Authentication guide](https://developers.docusign.com/esign-rest-api/guides/authentication)
195+
for information on choosing the right authentication flow for your application.
196+
179197
### License
180198
This repository uses the MIT License. See the LICENSE file for more information.
181199

182200
### Pull Requests
183201
Pull requests are welcomed. Pull requests will only be considered if their content
184-
uses the MIT License.
202+
uses the MIT License.

app/ds_config.py renamed to app/ds_config_sample.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"signer_name": "{USER_FULLNAME}",
1010
"app_url": "{APP_URL}", # The url of the application. Eg http://localhost:5000
1111
# NOTE: You must add a Redirect URI of appUrl/ds/callback to your Integration Key.
12-
# Example: http:#localhost:5000/ds/callback
12+
# Example: http://localhost:5000/ds/callback
1313
"authorization_server": "https://account-d.docusign.com",
1414
"allow_silent_authentication": True, # a user can be silently authenticated if they have an
1515
# active login session on another tab of the same browser
@@ -29,7 +29,7 @@
2929

3030
DS_JWT = {
3131
"ds_client_id": "{CLIENT_ID}",
32-
"ds_impersonated_user_id": "{IMPERSONATED_USER_ID}", # the id of the user
33-
"private_key_file": "private.key", # path to file which hold private key or private key itself
34-
"authorization_server": "account-d.docusign.com",
32+
"ds_impersonated_user_id": "{IMPERSONATED_USER_ID}", # The id of the user.
33+
"private_key_file": "./private.key", # Create a new file in your repo source folder named private.key then copy and paste your RSA private key there and save it.
34+
"authorization_server": "account-d.docusign.com"
3535
}

app/templates/home.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
<!-- IF not signed in -->
88
<div class="jumbotron">
99
<h1 class="display-4">Welcome!</h1>
10-
<p class="Xlead">Welcome to the DocuSign Python code examples with
11-
OAuth Authorization Code Grant.</p>
10+
<p class="Xlead">Welcome to the DocuSign Python examples using multiple OAuth flows (JWT and Authorization Code Grant).</p>
1211
</div>
1312
{% endif %}
1413

@@ -18,12 +17,10 @@ <h1 class="display-4">Welcome!</h1>
1817

1918
<div id="index-page">
2019
<h2>Welcome</h2>
21-
<p>This launcher both demonstrates use of the OAuth Authorization Code Grant flow and includes multiple
22-
usage examples for the DocuSign eSignature REST API.</p>
20+
<p>This launcher includes the following examples for the DocuSign eSignature REST API.</p>
2321

2422
{% if show_doc %}
25-
<p><a target='_blank' href='{{ documentation | safe }}'>Documentation</a> on using OAuth Authorization Code Grant from a
26-
Python Flask application.</p>
23+
<p><a target='_blank' href='{{ documentation | safe }}'>Documentation</a> on using JWT or Authorization Code Grant from a Python Flask application.</p>
2724
{% endif %}
2825

2926
<h2>Basic Examples</h2>

0 commit comments

Comments
 (0)