|
| 1 | +# C#: Authorization Code Grant Examples |
| 2 | + |
| 3 | +### Github repo: eg-03-csharp-auth-code-grant-core |
| 4 | +## Introduction |
| 5 | +This repo is a C# .NET Core MVC application that demonstrates: |
| 6 | + |
| 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 | +1. **Embedded Signing Ceremony.** |
| 12 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg001EmbeddedSigningController.cs) |
| 13 | + This example sends an envelope, and then uses an embedded signing ceremony for the first signer. |
| 14 | + With embedded signing, the DocuSign signing ceremony is initiated from your website. |
| 15 | +1. **Send an envelope with a remote (email) signer and cc recipient.** |
| 16 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg002SigningViaEmailController.cs) |
| 17 | + The envelope includes a pdf, Word, and HTML document. |
| 18 | + Anchor text ([AutoPlace](https://support.docusign.com/en/guides/AutoPlace-New-DocuSign-Experience)) is used to position the signing fields in the documents. |
| 19 | +1. **List envelopes in the user's account.** |
| 20 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg003ListEnvelopesController.cs) |
| 21 | + The envelopes' current status is included. |
| 22 | +1. **Get an envelope's basic information.** |
| 23 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/eg004EnvelopeInfoController.cs) |
| 24 | + The example lists the basic information about an envelope, including its overall status. |
| 25 | +1. **List an envelope's recipients** |
| 26 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg005EnvelopeRecipientsController.cs) |
| 27 | + Includes current recipient status. |
| 28 | +1. **List an envelope's documents.** |
| 29 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg006EnvelopeDocsController.cs) |
| 30 | +1. **Download an envelope's documents.** |
| 31 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg007EnvelopeGetDocController.cs) |
| 32 | + The example can download individual |
| 33 | + documents, the documents concatenated together, or a zip file of the documents. |
| 34 | +1. **Programmatically create a template.** |
| 35 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg008CreateTemplateController.cs) |
| 36 | +1. **Send an envelope using a template.** |
| 37 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg009UseTemplateController.cs) |
| 38 | +1. **Send an envelope and upload its documents with multpart binary transfer.** |
| 39 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg010SendBinaryDocsController.cs) |
| 40 | + Binary transfer is 33% more efficient than using Base64 encoding. |
| 41 | +1. **Embedded sending.** |
| 42 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg011EmbeddedSendingController.cs) |
| 43 | + Embeds the DocuSign web tool (NDSE) in your web app to finalize or update |
| 44 | + the envelope and documents before they are sent. |
| 45 | +1. **Embedded DocuSign web tool (NDSE).** |
| 46 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg012EmbeddedConsoleController.cs) |
| 47 | +1. **Embedded Signing Ceremony from a template with an added document.** |
| 48 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg013AddDocToTemplateController.cs) |
| 49 | + This example sends an envelope based on a template. |
| 50 | + In addition to the template's document(s), the example adds an |
| 51 | + additional document to the envelope by using the |
| 52 | + [Composite Templates](https://developers.docusign.com/esign-rest-api/guides/features/templates#composite-templates) |
| 53 | + feature. |
| 54 | +1. **Payments example: an order form, with online payment by credit card.** |
| 55 | + [Source.](https://github.com/docusign/eg-03-csharp-auth-code-grant-core/blob/master/eg-03-csharp-auth-code-grant-core/Controllers/Eg014CollectPaymentController.cs) |
| 56 | + |
| 57 | +## Installation |
| 58 | + |
| 59 | +### Prerequisites |
| 60 | +1. A DocuSign Developer Sandbox account (email and password) on [demo.docusign.net](https://demo.docusign.net). |
| 61 | + Create a [free account](https://go.docusign.com/o/sandbox/). |
| 62 | +1. A DocuSign Integration Key (a client ID) that is configured to use the |
| 63 | + OAuth Authorization Code flow. |
| 64 | + You will need the **Integration Key** itself, and its **secret**. |
| 65 | + |
| 66 | + If you use this example on your own workstation, |
| 67 | + the Integration key must include a **Redirect URI** of `http://localhost:8080/ds/callback` |
| 68 | + |
| 69 | + If you will not be running the example on your own workstation, |
| 70 | + use the appropriate DNS name and port instead of `localhost` |
| 71 | + |
| 72 | +1. C# .NET Core version 2.1 or later. |
| 73 | +1. A name and email for a signer, and a name and email for a cc recipient. |
| 74 | + |
| 75 | +### Installation steps |
| 76 | +* Download or clone this repository. |
| 77 | +* The repository includes a Visual Studio 2017 solution file and |
| 78 | + NuGet package references in the project file. |
| 79 | +* Configure the project by editing the existing project file |
| 80 | + `appsettings.json` |
| 81 | + |
| 82 | + See the Configuration section, below, for more information. |
| 83 | + |
| 84 | +### Configuration |
| 85 | +**appsettings.json** is the configuration file. |
| 86 | + |
| 87 | +Replace the {CLIENT_ID}, {CLIENT_SECRET}, {USER_EMAIL}, and {USER_FULLNAME} |
| 88 | +text with your values. Do not leave the braces { } in the configuration file. |
| 89 | + |
| 90 | +The Client_id (Integration Key) and its secret are private. Please do not |
| 91 | +store the appsettings file in your code repository after you have added |
| 92 | +the private information to it. |
| 93 | + |
| 94 | +To update to production, change all of the authorization service |
| 95 | +**https://account-d.docusign.com** addresses to **https://account.docusign.com** |
| 96 | + |
| 97 | +#### Payments code example |
| 98 | +To use the payments example, create a |
| 99 | +test payments gateway for your developer sandbox account. |
| 100 | + |
| 101 | +See the |
| 102 | +[PAYMENTS_INSTALLATION.md](https://github.com/docusign/eg-03-python-auth-code-grant/blob/master/PAYMENTS_INSTALLATION.md) |
| 103 | +file for instructions. |
| 104 | + |
| 105 | +Then add the payment gateway account id to the **appsettings.json** file. |
| 106 | + |
| 107 | +### Running the example |
| 108 | +Build and then start the solution. |
| 109 | + |
| 110 | +Your default browser will be opened to https://localhost:8080 and you will |
| 111 | +see the application's home page. |
| 112 | + |
| 113 | +## Using the examples with other authentication flows |
| 114 | + |
| 115 | +The examples in this repository can also be used with either the |
| 116 | +Implicit Grant or JWT OAuth flows. |
| 117 | +See the [Authentication guide](https://developers.docusign.com/esign-rest-api/guides/authentication) |
| 118 | +for information on choosing the right authentication flow for your application. |
| 119 | + |
| 120 | +## License and additional information |
| 121 | + |
| 122 | +### License |
| 123 | +This repository uses the MIT License. See the LICENSE file for more information. |
| 124 | + |
| 125 | +### Pull Requests |
| 126 | +Pull requests are welcomed. Pull requests will only be considered if their content |
| 127 | +uses the MIT License. |
0 commit comments