Get An Access Token in C#
In this section we're going to request the simplest details possible from the Legalesign API in order to check that everything is working for you. This example will dump the results out into the terminal for you to see.
Command Line Example
CLIExample.cs
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 CLILegalesignExamples
{
class CLILegalQLExample
{
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 token = await CLILegalQLExample.GetCredsAsync(args[0], args[1]);
Console.WriteLine(token)
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;
}
}
}
Using the Token in Code
Now you know how to get an access token you can run any GraphQL query or mutation that you require.
Next Steps
Find an example of a task you want to integrate into your system.