-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
89 lines (74 loc) · 3.01 KB
/
Program.cs
File metadata and controls
89 lines (74 loc) · 3.01 KB
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
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using Amazon.CognitoIdentity;
using Amazon.CognitoIdentityProvider;
using Amazon.Extensions.CognitoAuthentication;
using Amazon.Runtime;
using System.Threading.Tasks;
namespace CSharpLegalesignExamples
{
class CSharpLegalesignExamples
{
static async Task Main(string[] args)
{
Console.WriteLine("Legalesign C# Command Line Example");
var httpClient = new HttpClient
{
BaseAddress = new Uri("https://graphql.uk.legalesign.com/graphql")
};
// First we need a valid security token
string tokens = await CSharpLegalesignExamples.GetCredsAsync(args[0], args[1]);
httpClient.DefaultRequestHeaders.Add("User-Agent", "LegalesignCLI");
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokens);
var queryObject = new
{
query = @"query {
user {
email
firstName
lastName
}
}",
variables = new { }
};
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
Content = new StringContent(JsonSerializer.Serialize(queryObject), Encoding.UTF8, "application/json")
};
dynamic responseObj;
using (var response = await httpClient.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var responseString = await response.Content.ReadAsStringAsync();
if (responseString != null)
{
responseObj = JsonSerializer.Deserialize<dynamic>(responseString);
Console.WriteLine(responseObj);
}
}
Console.ReadLine();
}
static async Task<string> GetCredsAsync(string username, string password)
{
// These are the general purpose pool and client id - if you have dedicated ones insert them here.
var poolData = new
{
UserPoolId = "eu-west-2_NUPAjABy7",
ClientId = "38kn0eb9mf2409t6mci98eqdvt",
};
AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials());
CognitoUserPool userPool = new CognitoUserPool(poolData.UserPoolId, poolData.ClientId, provider);
CognitoUser user = new CognitoUser(username, poolData.ClientId, userPool, provider);
InitiateSrpAuthRequest authRequest = new InitiateSrpAuthRequest()
{
Password = password
};
AuthFlowResponse authResponse = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false);
return authResponse.AuthenticationResult.AccessToken;
}
}
}