Skip to content

Commit ba311a3

Browse files
committed
initial draft of the example
1 parent c28f469 commit ba311a3

21 files changed

+1081
-0
lines changed

ExamplesAPIType.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public enum ExamplesApiType
4343
/// </summary>
4444
[Description("con")]
4545
Connect = 5,
46+
47+
/// <summary>
48+
/// Web Forms API
49+
/// </summary>
50+
[Description("web")]
51+
WebForms = 6,
4652
}
4753

4854
public static class ExamplesApiTypeExtensions

ExamplesApiTypeExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public enum ExamplesApiType
4343
/// </summary>
4444
[Description("con")]
4545
Connect = 5,
46+
47+
/// <summary>
48+
/// Web Forms API
49+
/// </summary>
50+
[Description("web")]
51+
WebForms = 6,
4652
}
4753

4854
public static class ExamplesApiTypeExtensions

JWTAuth.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public static OAuthToken AuthenticateWithJwt(string api, string clientId, string
7878
});
7979
}
8080

81+
if (apiType == ExamplesApiType.WebForms)
82+
{
83+
scopes.Add("webforms_manage");
84+
}
85+
8186
return docuSignClient.RequestJWTUserToken(
8287
clientId,
8388
impersonatedUserId,

launcher-csharp.Tests/JwtLoginMethodUnitTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ private string BuildConsentUrl(ExamplesApiType apiType, TestConfig testConfig)
9292
scopes += "%20user_read%20user_write%20organization_read%20account_read%20group_read%20"
9393
+ "permission_read%20identity_provider_read%20domain_read%20user_data_redact%20"
9494
+ "asset_group_account_read%20asset_group_account_clone_write%20asset_group_account_clone_read";
95+
} else if (apiType == ExamplesApiType.WebForms)
96+
{
97+
scopes += "%20webforms_manage";
9598
}
9699

97100
string caret = "";

launcher-csharp/Common/IRequestItemsService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public interface IRequestItemsService
3434

3535
public string TemplateId { get; set; }
3636

37+
public string WebFormsTemplateId { get; set; }
38+
3739
public string PausedEnvelopeId { get; set; }
3840

3941
public string Status { get; set; }

launcher-csharp/Common/LocalsFilter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public void OnActionExecuting(ActionExecutingContext context)
9797
BasePath = identity.FindFirst(x => x.Type.Equals("base_uri")).Value,
9898
RoomsApiBasePath = this.configuration["DocuSign:RoomsApiEndpoint"],
9999
AdminApiBasePath = this.configuration["DocuSign:AdminApiEndpoint"],
100+
WebFormsBasePath = this.configuration["DocuSign:WebFormsBasePath"],
100101
}
101102
:
102103
new Session
@@ -106,6 +107,7 @@ public void OnActionExecuting(ActionExecutingContext context)
106107
BasePath = this.requestItemsService.Session.BasePath,
107108
RoomsApiBasePath = this.configuration["DocuSign:RoomsApiEndpoint"],
108109
AdminApiBasePath = this.configuration["DocuSign:AdminApiEndpoint"],
110+
WebFormsBasePath = this.configuration["DocuSign:WebFormsBasePath"],
109111
};
110112

111113
this.requestItemsService.Session = locals.Session;

launcher-csharp/Common/RequestItemsService.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ public string TemplateId
148148
set => this.cache.Set(this.GetKey("TemplateId"), value);
149149
}
150150

151+
public string WebFormsTemplateId
152+
{
153+
get => this.cache.Get<string>(this.GetKey("WebFormsTemplateId"));
154+
set => this.cache.Set(this.GetKey("WebFormsTemplateId"), value);
155+
}
156+
151157
public string ClickwrapId
152158
{
153159
get => this.cache.Get<string>(this.GetKey("ClickwrapId"));
@@ -206,6 +212,7 @@ public void UpdateUserFromJwt()
206212
BasePath = account.BaseUri,
207213
RoomsApiBasePath = this.Configuration["DocuSign:RoomsApiEndpoint"],
208214
AdminApiBasePath = this.Configuration["DocuSign:AdminApiEndpoint"],
215+
WebFormsBasePath = this.Configuration["DocuSign:WebFormsBasePath"],
209216
};
210217
}
211218

@@ -255,6 +262,10 @@ public string IdentifyApiOfCodeExample(string eg)
255262
{
256263
currentApiType = ExamplesApiType.Connect.ToString();
257264
}
265+
else if (eg.Contains(ExamplesApiType.WebForms.ToKeywordString()))
266+
{
267+
currentApiType = ExamplesApiType.WebForms.ToString();
268+
}
258269
else
259270
{
260271
currentApiType = ExamplesApiType.ESignature.ToString();

launcher-csharp/Startup.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public Startup(IConfiguration configuration)
7777
"asset_group_account_clone_write",
7878
"asset_group_account_clone_read",
7979
});
80+
81+
this.apiTypes.Add(ExamplesApiType.WebForms, new List<string>
82+
{
83+
"signature", "webforms_manage",
84+
});
8085
}
8186

8287
public IConfiguration Configuration { get; }

launcher-csharp/Views/Home/Index.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
: ((ApIs) api).Name.ToLower() == ExamplesApiType.Monitor.ToString().ToLower() ? ExamplesApiType.Monitor.ToKeywordString()
4444
: ((ApIs) api).Name.ToLower() == ExamplesApiType.Rooms.ToString().ToLower() ? ExamplesApiType.Rooms.ToKeywordString()
4545
: ((ApIs) api).Name.ToLower() == ExamplesApiType.Connect.ToString().ToLower() ? ExamplesApiType.Connect.ToKeywordString()
46+
: ((ApIs) api).Name.ToLower() == ExamplesApiType.WebForms.ToString().ToLower() ? ExamplesApiType.WebForms.ToKeywordString()
4647
: ExamplesApiType.Admin.ToKeywordString();
4748

4849
@foreach(var exampleGroup in api.Groups)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// <copyright file="CreateAndEmbedForm.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.WebForms.Controllers
6+
{
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Linq;
10+
using DocuSign.CodeExamples.Common;
11+
using DocuSign.CodeExamples.Controllers;
12+
using DocuSign.CodeExamples.Models;
13+
using DocuSign.eSign.Client;
14+
using DocuSign.eSign.Model;
15+
using DocuSign.WebForms.Examples;
16+
using DocuSign.WebForms.Model;
17+
using Microsoft.AspNetCore.Mvc;
18+
using Microsoft.Extensions.Configuration;
19+
20+
[Area("WebForms")]
21+
[Route("web001")]
22+
public class CreateAndEmbedForm : EgController
23+
{
24+
private IConfiguration configuration;
25+
26+
public CreateAndEmbedForm(
27+
DsConfiguration config,
28+
IConfiguration configuration,
29+
LauncherTexts launcherTexts,
30+
IRequestItemsService requestItemsService)
31+
: base(config, launcherTexts, requestItemsService)
32+
{
33+
this.configuration = configuration;
34+
this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.Connect);
35+
this.ViewBag.title = this.CodeExampleText.ExampleName;
36+
}
37+
38+
public override string EgName => "web001";
39+
40+
[SetViewBag]
41+
[HttpPost]
42+
[ValidateAntiForgeryToken]
43+
public ActionResult CheckTheTemplates()
44+
{
45+
string basePath = this.RequestItemsService.Session.BasePath + "/restapi";
46+
string accessToken = this.RequestItemsService.User.AccessToken;
47+
string accountId = this.RequestItemsService.Session.AccountId;
48+
49+
var docuSignClient = new DocuSignClient(basePath);
50+
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
51+
52+
List<EnvelopeTemplate> templates = CreateAndEmbedFormService.CheckIfTemplateExists(docuSignClient, accountId);
53+
if (templates == null || templates.Count == 0)
54+
{
55+
var template = CreateAndEmbedFormService.CreateTemplate(
56+
docuSignClient,
57+
accountId,
58+
this.Config.DocumentTemplatePdf);
59+
60+
this.RequestItemsService.WebFormsTemplateId = template.TemplateId;
61+
}
62+
else
63+
{
64+
this.RequestItemsService.WebFormsTemplateId = templates.First().TemplateId;
65+
}
66+
67+
CreateAndEmbedFormService.AddTemplateIdToForm(
68+
this.Config.WebFormConfig,
69+
this.RequestItemsService.WebFormsTemplateId);
70+
71+
return this.View("embedForm");
72+
}
73+
74+
[MustAuthenticate]
75+
[SetViewBag]
76+
[Route("EmbedForm")]
77+
[HttpPost]
78+
[ValidateAntiForgeryToken]
79+
public ActionResult EmbedForm(string formId)
80+
{
81+
string basePath = this.RequestItemsService.Session.WebFormsBasePath;
82+
string accessToken = this.RequestItemsService.User.AccessToken;
83+
string accountId = this.RequestItemsService.Session.AccountId;
84+
85+
var docuSignClient = new DocuSign.WebForms.Client.DocuSignClient(basePath);
86+
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
87+
88+
WebFormInstance form = CreateAndEmbedFormService.CreateInstance(
89+
docuSignClient,
90+
Guid.Parse(accountId),
91+
formId);
92+
93+
this.ViewBag.InstanceToken = form.InstanceToken;
94+
this.ViewBag.Url = form.FormUrl;
95+
this.ViewBag.IntegrationKey = this.configuration["DocuSign:ClientId"];
96+
97+
return this.View("Embed");
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)