Skip to content

docusign/code-examples-python

 
 

Repository files navigation

Python: Authorization Code Grant Examples

Github repo: eg-03-python-auth-code-grant

Introduction

This repo is a Python 3 application that demonstrates:

  • Authentication with DocuSign via the Authorization Code Grant flow. When the token expires, the user is asked to re-authenticate. The refresh token is not used in this example.
  1. Embedded Signing Ceremony. Source. This example sends an envelope, and then uses an embedded signing ceremony for the first signer. With embedded signing, the DocuSign signing ceremony is initiated from your website.
  2. Send an envelope with a remote (email) signer and cc recipient. Source. The envelope includes a pdf, Word, and HTML document. Anchor text (AutoPlace) is used to position the signing fields in the documents.
  3. List envelopes in the user's account. Source. The envelopes' current status is included.
  4. Get an envelope's basic information. Source. The example lists the basic information about an envelope, including its overall status.
  5. List an envelope's recipients Source. Includes current recipient status.
  6. List an envelope's documents. Source.
  7. Download an envelope's documents. Source. The example can download individual documents, the documents concatenated together, or a zip file of the documents.
  8. Programmatically create a template. Source.
  9. Send an envelope using a template. Source.
  10. Send an envelope and upload its documents with multpart binary transfer. Source. Binary transfer is 33% more efficient than using Base64 encoding.
  11. Embedded sending. Source. Embeds the DocuSign web tool (NDSE) in your web app to finalize or update the envelope and documents before they are sent.
  12. Embedded DocuSign web tool (NDSE). Source.
  13. Embedded Signing Ceremony from a template with an added document. Source. This example sends an envelope based on a template. In addition to the template's document(s), the example adds an additional document to the envelope by using the Composite Templates feature.
  14. Payments example: an order form, with online payment by credit card. Source.

Installation

Prerequisites

  1. A DocuSign Developer Sandbox account (email and password) on demo.docusign.net. Create a free account.

  2. 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.

    If you use this example on your own workstation, the Integration key must include a Redirect URI of http://localhost:5000/ds/callback

    If you will not be running the example on your own workstation, use the appropriate DNS name and port instead of localhost

    This video demonstrates how to create an Integration Key (client id) for a user application like this example. Note that the redirect url for your Integration Key will be http://localhost:5000/ds/callback if you use the default Python settings.

  3. Python 3.

  4. A name and email for a signer, and a name and email for a cc recipient.

Installation steps

  1. Download or clone this repository to your workstation to directory eg-03-python-auth-code-grant

  2. cd eg-03-python-auth-code-grant

  3. pip3 install -r requirements.txt (or pipenv can be used)

  4. Update the file app/ds_config.py with the Integration Key and other settings.

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

  5. python3 run.py

  6. Open a browser to http://localhost:5000

Payments code example

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

See the PAYMENTS_INSTALLATION.md file for instructions.

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

Using the examples with other authentication flows

The examples in this repository can also be used with either the Implicit Grant or JWT OAuth flows. See the Authentication guide for information on choosing the right authentication flow for your application.

License and additional information

License

This repository uses the MIT License. See the LICENSE file for more information.

Pull Requests

Pull requests are welcomed. Pull requests will only be considered if their content uses the MIT License.