Skip to content

Commit a6b7e10

Browse files
authored
Merge pull request #160 from docusign/feature/web-forms-code-example
Web forms code example
2 parents e704573 + 4f92b78 commit a6b7e10

25 files changed

+3767
-2603
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,5 @@ __pycache__/
263263
#configuration files (secrets), should not be checked in to source control
264264
appsettings.json
265265
private.key
266-
app.config
266+
app.config
267+
web-form-config.json

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: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ namespace DocuSign.CodeExamples
77
{
88
using System;
99
using System.Collections.Generic;
10+
using System.Linq;
1011
using System.Net.Http;
1112
using System.Net.Http.Headers;
1213
using System.Security.Claims;
1314
using System.Text.Json;
15+
using System.Text.RegularExpressions;
1416
using System.Threading.Tasks;
17+
using System.Web;
1518
using DocuSign.CodeExamples.Common;
1619
using DocuSign.CodeExamples.Models;
1720
using DocuSign.Rooms.Api;
@@ -35,7 +38,7 @@ public Startup(IConfiguration configuration)
3538
{
3639
this.Configuration = configuration;
3740

38-
this.apiTypes.Add(ExamplesApiType.ESignature, new List<string> { "signature" });
41+
this.apiTypes.Add(ExamplesApiType.ESignature, new List<string> { "signature", });
3942

4043
this.apiTypes.Add(ExamplesApiType.Rooms, new List<string>
4144
{
@@ -77,6 +80,11 @@ public Startup(IConfiguration configuration)
7780
"asset_group_account_clone_write",
7881
"asset_group_account_clone_read",
7982
});
83+
84+
this.apiTypes.Add(ExamplesApiType.WebForms, new List<string>
85+
{
86+
"signature", "webforms_manage",
87+
});
8088
}
8189

8290
public IConfiguration Configuration { get; }
@@ -175,28 +183,7 @@ public void ConfigureServices(IServiceCollection services)
175183
{
176184
List<string> scopesForCurrentApi = this.apiTypes.GetValueOrDefault(Enum.Parse<ExamplesApiType>(this.Configuration["API"]));
177185

178-
foreach (var api in this.apiTypes)
179-
{
180-
if (this.Configuration["API"] != api.Key.ToString())
181-
{
182-
foreach (var scope in api.Value)
183-
{
184-
if (scopesForCurrentApi != null && !scopesForCurrentApi.Contains(scope))
185-
{
186-
var scopeWithSeperator = scope + "%20";
187-
188-
if (redirectContext.RedirectUri.Contains(scopeWithSeperator))
189-
{
190-
redirectContext.RedirectUri = redirectContext.RedirectUri.Replace(scopeWithSeperator, string.Empty);
191-
}
192-
else
193-
{
194-
redirectContext.RedirectUri = redirectContext.RedirectUri.Replace(scope, string.Empty);
195-
}
196-
}
197-
}
198-
}
199-
}
186+
redirectContext.RedirectUri = this.UpdateRedirectUriScopes(redirectContext.RedirectUri, scopesForCurrentApi);
200187

201188
redirectContext.HttpContext.Response.Redirect(redirectContext.RedirectUri);
202189
return Task.FromResult(0);
@@ -327,5 +314,13 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
327314

328315
return keyValue;
329316
}
317+
318+
private string UpdateRedirectUriScopes(string uri, List<string> wantedScopes)
319+
{
320+
const string pattern = @"(?:&|\?)scope=([^&]+)";
321+
322+
var encodedScopes = string.Join(" ", wantedScopes);
323+
return Regex.Replace(uri, pattern, $"&scope={HttpUtility.UrlPathEncode(encodedScopes)}");
324+
}
330325
}
331326
}

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)

0 commit comments

Comments
 (0)