-
Notifications
You must be signed in to change notification settings - Fork 62
/
JWTAuth.cs
99 lines (92 loc) · 3.21 KB
/
JWTAuth.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// <copyright file="JWTAuth.cs" company="DocuSign">
// Copyright (c) DocuSign. All rights reserved.
// </copyright>
namespace DocuSign.CodeExamples.Authentication
{
using System;
using System.Collections.Generic;
using DocuSign.CodeExamples.Common;
using DocuSign.eSign.Client;
using static DocuSign.eSign.Client.Auth.OAuth;
public static class JwtAuth
{
/// <summary>
/// Uses Json Web Token (JWT) Authentication Method to obtain the necessary information needed to make API calls.
/// </summary>
/// <returns>Auth token needed for API calls</returns>
public static OAuthToken AuthenticateWithJwt(string api, string clientId, string impersonatedUserId, string authServer, byte[] privateKeyBytes)
{
var docuSignClient = new DocuSignClient();
var apiType = Enum.Parse<ExamplesApiType>(api);
var scopes = new List<string>
{
"signature",
"impersonation",
};
if (apiType == ExamplesApiType.Rooms)
{
scopes.AddRange(new List<string>
{
"dtr.rooms.read",
"dtr.rooms.write",
"dtr.documents.read",
"dtr.documents.write",
"dtr.profile.read",
"dtr.profile.write",
"dtr.company.read",
"dtr.company.write",
"room_forms",
});
}
if (apiType == ExamplesApiType.Click)
{
scopes.AddRange(new List<string>
{
"click.manage",
"click.send",
});
}
if (apiType == ExamplesApiType.Monitor)
{
scopes.AddRange(new List<string>
{
"signature",
"impersonation",
});
}
if (apiType == ExamplesApiType.Admin)
{
scopes.AddRange(new List<string>
{
"user_read",
"user_write",
"account_read",
"organization_read",
"group_read",
"permission_read",
"identity_provider_read",
"domain_read",
"user_data_redact",
"asset_group_account_read",
"asset_group_account_clone_write",
"asset_group_account_clone_read",
"organization_sub_account_write",
"organization_sub_account_read",
});
}
if (apiType == ExamplesApiType.WebForms)
{
scopes.Add("webforms_read");
scopes.Add("webforms_instance_write");
scopes.Add("webforms_instance_read");
}
return docuSignClient.RequestJWTUserToken(
clientId,
impersonatedUserId,
authServer,
privateKeyBytes,
1,
scopes);
}
}
}