Authorize Your Code
Any request for information or updates that you make to the GraphQL API will need to carry an authentication header for a valid, current account.
Create Code to Authorize Your requests
Let's take a quick look at how you can get the authorization token for your requests before we wade into the
complete example for our first GraphQL query. This is general-purpose code for getting your authentication token (a Bearer
token)
you can use to perform all other tasks against the Legalesign platform.
You don't need to copy this into your project yet - we'll provide a complete sample in the next step.
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;
}
You can see that we authenticate the user credentials being passed in, then the response is an AccessToken
valid for
the current session. You may need to write any long running code you have to check that the token you have
is still valid, and if not, sign in again to get a new token.
The UserPoolId
and ClientId
that are included in this code are the general public values. If we have provided you
with dedicated values of these for your organisation, you should use those instead. For the purposes of almost all
customers the general identity pool is correct.
Let's move on to executing a query against the API.