Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronWDS committed Jan 10, 2024
2 parents 833f9cc + cdd83f1 commit 95108a6
Show file tree
Hide file tree
Showing 20 changed files with 1,773 additions and 1,563 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ dotnet_diagnostic.SA1651.severity = error
dotnet_diagnostic.SA1648.severity = error

# SA1649: File name should match first type name
dotnet_diagnostic.SA1649.severity = error
dotnet_diagnostic.SA1649.severity = suggestion

# SA1640: File header should have valid company text
dotnet_diagnostic.SA1640.severity = error
Expand Down
6 changes: 6 additions & 0 deletions ExamplesAPIType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public enum ExamplesApiType
/// </summary>
[Description("aeg")]
Admin = 4,

/// <summary>
/// Connect API
/// </summary>
[Description("con")]
Connect = 5,
}

public static class ExamplesApiTypeExtensions
Expand Down
6 changes: 6 additions & 0 deletions ExamplesApiTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public enum ExamplesApiType
/// </summary>
[Description("aeg")]
Admin = 4,

/// <summary>
/// Connect API
/// </summary>
[Description("con")]
Connect = 5,
}

public static class ExamplesApiTypeExtensions
Expand Down
2 changes: 1 addition & 1 deletion JWT-Console/App.config.Example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<add key="ClientId" value="{INTEGRATION_KEY_JWT}"/>
<add key="AuthServer" value="account-d.docusign.com"/>
<add key="ImpersonatedUserID" value="{IMPERSONATED_USER_ID}"/>
<add key="PrivateKeyFile" value="..\..\..\private.key"/>
<add key="PrivateKeyFile" value="../../../private.key"/>
</appSettings>
</configuration>
2 changes: 1 addition & 1 deletion JWT-Console/JWT-Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\ExamplesApiTypeExtensions.cs" Link="ExamplesApiTypeExtensions.cs" />
<Compile Include="..\DSHelper.cs" Link="DSHelper.cs" />
<Compile Include="..\ExamplesAPIType.cs" Link="ExamplesAPIType.cs" />
<Compile Include="..\JWTAuth.cs" Link="JWTAuth.cs" />
<Compile Include="..\launcher-csharp\eSignature\Examples\SigningViaEmail.cs" Link="SigningViaEmail.cs" />
</ItemGroup>
Expand Down
9 changes: 8 additions & 1 deletion JWT-Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ static void Main(string[] args)
// build a URL to provide consent for this Integration Key and this userId
string url = "https://" + ConfigurationManager.AppSettings["AuthServer"] + "/oauth/auth?response_type=code" + caret + "&scope=impersonation%20signature" + caret +
"&client_id=" + ConfigurationManager.AppSettings["ClientId"] + caret + "&redirect_uri=" + DevCenterPage;
Console.WriteLine($"Consent is required - launching browser (URL is {url.Replace(caret, "")})");

string consentRequiredMessage = $"Consent is required - launching browser (URL is {url})";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
consentRequiredMessage = consentRequiredMessage.Replace(caret, "");
}

Console.WriteLine(consentRequiredMessage);

// Start new browser window for login and consent to this app by DocuSign user
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Expand Down
2 changes: 1 addition & 1 deletion Quick_ACG/Quick_ACG.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\ExamplesApiTypeExtensions.cs" Link="ExamplesApiTypeExtensions.cs" />
<Compile Include="..\ExamplesAPIType.cs" Link="ExamplesAPIType.cs" />
<Compile Include="..\launcher-csharp\Common\SetViewBagAttribute.cs" Link="Common\SetViewBagAttribute.cs" />
<Compile Include="..\launcher-csharp\EmbeddedSigningCeremony.cs" Link="EmbeddedSigningCeremony.cs" />
<Compile Include="..\launcher-csharp\eSignature\Controllers\EmbeddedSigningCeremony.cs" Link="eSignature\Controllers\EmbeddedSigningCeremony.cs" />
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@ Also, in order to select JSON Web Token authentication in the launcher, in launc
1. When prompted, log in to your DocuSign developer account. If this is your first time using the app, select **ACCEPT** at the consent window.
1. Select your desired code example.

## Authorization Code Grant embedded signing example:
1. Double click the Quick_ACG.csproj (or Quick_ACG-2019.csproj for VS 2109) file in the Quick_ACG folder of your Quickstart project.
1. Select the green Play IIS Express button.

## JWT grant remote signing project
See [DocuSign Quickstart overview](https://developers.docusign.com/docs/esign-rest-api/quickstart/overview/) on the DocuSign Developer Center for more information on how to run the JWT grant remote signing project.
1. Double click the JWT-Console.csproj (or JWT-Console-2019.csproj for VS 2109) file in the JWT-Console folder of your Quickstart project.
1. Select the green Play JWT Console button.

## Payments code example
To use the payments code example, create a test payment gateway on the [Payments](https://admindemo.docusign.com/authenticate?goTo=payments) page in your developer account. See [Configure a payment gateway](./PAYMENTS_INSTALLATION.md) for details.
Expand All @@ -133,4 +138,4 @@ This repository uses the MIT License. See [LICENSE](./LICENSE) for details.

### Pull Requests
Pull requests are welcomed. Pull requests will only be considered if their content
uses the MIT License.
uses the MIT License.
4 changes: 4 additions & 0 deletions launcher-csharp/Common/RequestItemsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ public string IdentifyApiOfCodeExample(string eg)
{
currentApiType = ExamplesApiType.Admin.ToString();
}
else if (eg.Contains(ExamplesApiType.Connect.ToKeywordString()))
{
currentApiType = ExamplesApiType.Connect.ToString();
}
else
{
currentApiType = ExamplesApiType.ESignature.ToString();
Expand Down
41 changes: 41 additions & 0 deletions launcher-csharp/Connect/Controllers/ValidateWebhookMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// <copyright file="ValidateWebhookMessage.cs" company="DocuSign">
// Copyright (c) DocuSign. All rights reserved.
// </copyright>

namespace DocuSign.CodeExamples.Connect.Controllers
{
using DocuSign.CodeExamples.Common;
using DocuSign.CodeExamples.Controllers;
using DocuSign.CodeExamples.Models;
using DocuSign.Connect.Examples;
using Microsoft.AspNetCore.Mvc;

[Area("Connect")]
[Route("con001")]
public class ValidateWebhookMessage : EgController
{
public ValidateWebhookMessage(DsConfiguration config, LauncherTexts launcherTexts, IRequestItemsService requestItemsService)
: base(config, launcherTexts, requestItemsService)
{
this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.Connect);
this.ViewBag.title = this.CodeExampleText.ExampleName;
}

public override string EgName => "con001";

[SetViewBag]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ValidateMessageUsing(string hmacSecret, string jsonPayload)
{
jsonPayload = jsonPayload.Replace("\\", string.Empty);

string hashedOutput = HMACValidation.ComputeHash(hmacSecret, jsonPayload);

this.ViewBag.h1 = this.CodeExampleText.ExampleName;
this.ViewBag.message = this.CodeExampleText.ResultsPageText.Replace("{0}", hashedOutput);

return this.View("example_done");
}
}
}
33 changes: 33 additions & 0 deletions launcher-csharp/Connect/Examples/HMACValidation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// <copyright file="HMACValidation.cs" company="DocuSign">
// Copyright (c) DocuSign. All rights reserved.
// </copyright>

namespace DocuSign.Connect.Examples
{
using System;
using System.Security.Cryptography;
using System.Text;

public static class HMACValidation
{
//ds-snippet-start:Connect1Step1
public static string ComputeHash(string secret, string payload)
{
byte[] bytes = Encoding.UTF8.GetBytes(secret);
var hmac = new HMACSHA256(bytes);
bytes = Encoding.UTF8.GetBytes(payload);

return Convert.ToBase64String(hmac.ComputeHash(bytes));
}

public static bool HashIsValid(string secret, string payload, string verify)
{
ReadOnlySpan<byte> hashBytes = Convert.FromBase64String(ComputeHash(secret, payload));
ReadOnlySpan<byte> verifyBytes = Convert.FromBase64String(verify);

return CryptographicOperations.FixedTimeEquals(hashBytes, verifyBytes);
}

//ds-snippet-end:Connect1Step1
}
}
53 changes: 53 additions & 0 deletions launcher-csharp/Connect/Views/ValidateWebhookMessage/Con001.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@{
int formNumber = 0;
int hmacInputNumber = 0;
int jsonInputNumber = 1;
}

<h4>@Html.Raw(ViewBag.CodeExampleText.ExampleName)</h4>
<p>
@Html.Raw(ViewBag.CodeExampleText.ExampleDescription)
</p>

<partial name="../../../Views/Shared/LinkToMethodView" model="ViewBag.CodeExampleText" />
<p>
@Html.Raw(
@String.Format(
ViewBag.SupportingTexts.ViewSourceFile,
"<a target='_blank' href=" + @ViewBag.source + ">HMACValidation.cs</a>"
)
)
</p>

<p>
<b>Prerequisites:</b> See <a href="https://developers.docusign.com/platform/webhooks/connect/validate/">How to validate an HMAC signature</a>.
</p>

<form class="eg" action="" method="post" data-busy="form">
<div class="form-group" style="display: flex;">
<label for="hmacSecret" style="width: 50%;">
@Html.Raw(ViewBag.CodeExampleText.Forms[formNumber].Inputs[hmacInputNumber].InputName)
</label>

<input type="text"
class="form-control"
id="hmacSecret"
name="hmacSecret"
required/>
</div>
<div class="form-group">
<label for="jsonPayload">
@Html.Raw(ViewBag.CodeExampleText.Forms[formNumber].Inputs[jsonInputNumber].InputName)
</label>

<textarea
rows="6"
class="form-control"
id="jsonPayload"
name="jsonPayload"
required ></textarea>
</div>
<input type="hidden" name="_csrf" value="@ViewBag.csrfToken">
<button type="submit" class="btn btn-primary">@Html.Raw(ViewBag.SupportingTexts.SubmitButton)</button>
</form>

2 changes: 1 addition & 1 deletion launcher-csharp/Monitor/Examples/GetMonitoringDataFunc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public virtual IEnumerable<object> Invoke(string accessToken, string requestPath
//ds-snippet-start:Monitor1Step3
bool complete = false;
string cursorValue = string.Empty;
int limit = 2; // Amount of records you want to read in one request
int limit = 100; // Amount of records you want to read in one request
List<object> functionResult = new List<object>();

DataSetApi dataSetApi = new DataSetApi(apiClient);
Expand Down
1 change: 1 addition & 0 deletions launcher-csharp/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
: ((ApIs) api).Name.ToLower() == ExamplesApiType.Click.ToString().ToLower() ? ExamplesApiType.Click.ToKeywordString()
: ((ApIs) api).Name.ToLower() == ExamplesApiType.Monitor.ToString().ToLower() ? ExamplesApiType.Monitor.ToKeywordString()
: ((ApIs) api).Name.ToLower() == ExamplesApiType.Rooms.ToString().ToLower() ? ExamplesApiType.Rooms.ToKeywordString()
: ((ApIs) api).Name.ToLower() == ExamplesApiType.Connect.ToString().ToLower() ? ExamplesApiType.Connect.ToKeywordString()
: ExamplesApiType.Admin.ToKeywordString();

@foreach(var exampleGroup in api.Groups)
Expand Down
40 changes: 22 additions & 18 deletions launcher-csharp/Views/Shared/LinkToMethodView.cshtml
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
@model DocuSign.CodeExamples.ESignature.Models.CodeExampleText
@using Microsoft.EntityFrameworkCore.Migrations
@model DocuSign.CodeExamples.ESignature.Models.CodeExampleText
<p>
@if(Model.LinksToApiMethod.Count == 1)
@if (Model.LinksToApiMethod.Count != 0)
{
<span>@Html.Raw(ViewBag.SupportingTexts.ApiMethodUsed)</span>
}
else
{
<span>@Html.Raw(ViewBag.SupportingTexts.ApiMethodUsedPlural)</span>
}

@for(int i = 0; i < Model.LinksToApiMethod.Count; ++i)
{
<a target='_blank' href="@Model.LinksToApiMethod[i].Path">@Html.Raw(Model.LinksToApiMethod[i].PathName)</a>
@if(i + 1 == Model.LinksToApiMethod.Count)
@if (Model.LinksToApiMethod.Count == 1)
{
<span></span>
<span>@Html.Raw(ViewBag.SupportingTexts.ApiMethodUsed)</span>
}
else if(i + 1 == Model.LinksToApiMethod.Count - 1)
else
{
<span> and </span>
<span>@Html.Raw(ViewBag.SupportingTexts.ApiMethodUsedPlural)</span>
}
else

@for (int i = 0; i < Model.LinksToApiMethod.Count; ++i)
{
<span>, </span>
<a target='_blank' href="@Model.LinksToApiMethod[i].Path">@Html.Raw(Model.LinksToApiMethod[i].PathName)</a>
@if (i + 1 == Model.LinksToApiMethod.Count)
{
<span></span>
}
else if (i + 1 == Model.LinksToApiMethod.Count - 1)
{
<span> and </span>
}
else
{
<span>, </span>
}
}
}
</p>
Loading

0 comments on commit 95108a6

Please sign in to comment.