Arken Public API - Authentication

A couple of warnings:

  • Generated client authentication tokens must be stored securely in a cache of your choice; generating new authentication tokens frequently for each request causes performance issues against Arken application and must be reduced to at least one call per day. Generated Authentication tokens have a set time span expiration of 1 day (86400 secs).  
  • Please take note that the Authentication token indicated below is an example only.
  • All "createdOn" and "updatedOn" fields are set in UTC date format. All dates that has been passed through (i.e. dateOfBirth for Client) are retained as it is.Date Formats and Values

Overview

The Arken API is a RESTful web service that uses OAuth2/ Open ID Connect token protocol to authenticate 3rd party applications.


In this document:



Authentication

To be able to utilise the api endpoints, you need to generate a Bearer token in JWT format using the Arken API Client ID and Secret Key that will be assigned to you. To do this, you can either:

  • Open a new Command line and execute the curl command below:
curl --request POST \
  --url https://pre-arkenlegal.au.auth0.com/oauth/token \
  --header 'content-type: application/json' \
  --data '{"client_id":"<your_clientid_here>","client_secret":"<your_secret_here>","audience":"https://auth-aunz.api.arken.legal","grant_type":"client_credentials"}'


  • Create a .NET library project that will be referenced by your application by using this code here:
public static BearerToken GetBearerToken(string clientId, string clientSecret, string audience, string grantType, string authUrl)
{
	using (var client = new HttpClient())
	{
		client.BaseAddress = new Uri(authUrl);
		client.DefaultRequestHeaders.Accept.Clear();
		client.DefaultRequestHeaders.Accept.Add(
			new MediaTypeWithQualityHeaderValue("application/json"));

		var clientAccessData = new
		{
			client_id = clientId,
			client_secret = clientSecret,
			audience = audience,
			grant_type = grantType
		};

		var stringContent = new StringContent(JsonConvert.SerializeObject(clientAccessData), Encoding.UTF8, "application/json");

		try
		{
			// List data response.
			HttpResponseMessage response = client.PostAsync("oauth/token", stringContent).Result;  // Blocking call!

			if (response.IsSuccessStatusCode)
			{
				// Parse the response body. Blocking!
				var responseResult = response.Content.ReadAsStringAsync().Result;
				var bearerToken  = JsonConvert.DeserializeObject<BearerToken>(responseResult);
				return bearerToken;
			}
			else
			{
				throw new ApplicationException($"An error occured in call {(int)response.StatusCode}, {response.ReasonPhrase}");
			}
		}
		catch (Exception e)
		{
			Console.WriteLine(e);
			throw;
		}
	}
}


Either of these would return a Json content that contains the token you need to add to your HTTP headers, similar to the one below:

{
  "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik9UUXdOalE1TnpSRk9EUTNPVFl5UWtaRk0wSTFNVGcyUmpJNU1qRTBRekUxTXpkQk9UYzBNdyJ9.eyJpc3MiOiJodHRwczovL2RldmVsb3BtZW50LWFya2VubGVnYWwuYXUuYXV0aDAuY29tLyIsInN1YiI6Imx3TE5DMUlFMUp1a3EyNGJKYjdCdkRzNDVnd3AxVE84QGNsaWVudHMiLCJhdWQiOiJodHRwczovL2F1dGgtYXVuei5hcGkuYXJrZW4ubGVnYWwiLCJpYXQiOjE1Mjg2NzU2OTMsImV4cCI6MTUyODc2MjA5MywiYXpwIjoibHdMTkMxSUUxSnVrcTI0YkpiN0J2RHM0NWd3cDFUTzgiLCJzY29wZSI6ImNvbnN1bWVyOmFjY2VzcyIsImd0eSI6ImNsaWVudC1jcmVkZW50aWFscyJ9.D1cTIkeOf8Chsgune4X8GEasmLwwVEO7ozuD9j535UNRATJFwKL42j1wGOAJgjkcmEYmfqy1d1nBs94urgaUB472CG-Oyntg-7Lw-9Yw96nB9C7z6YGnvy1wVo1gdpI9ciUz8yf_Iq0YoWGzHrKYrIHoB-teRFtrvl1nzYcyK5I7APe9J1kazQ5JdId7y4ZGZVBXiNLCenuIzVO2Nqx98mXD-et7as5jL4dKGWq6Ja5_EKpvKD07Qi8EY3ajt4wRdDmqSjWJGzbmuyYLoI67jym1IJAuK4BcYqbe2ppEbgKvD7jrXmcGqNpAp6Z1i2IwNFWXKUjbscMeJPAgY3lXdg",
  "token_type": "Bearer"
}


Once the authentication token has been generated, we strongly advise to store this in a secure cache. A sample code on how to store it in memory is indicated below:

public ArkenAPIGateway GenerateClient()
{
	 BearerToken bearerToken = null;

	 ObjectCache cache = MemoryCache.Default;
	 var CacheKey = "BearerToken";

	 if (cache.Contains(CacheKey))
		 bearerToken = (BearerToken)cache.Get(CacheKey);
	 else
	 {
		 bearerToken = Access.GetBearerToken(_appSettings.ClientId, _appSettings.ClientSecret,
			 _appSettings.Audience, _appSettings.GrantType, _appSettings.TokenUrl);

		 CacheItemPolicy cacheItemPolicy = new CacheItemPolicy();
		 cacheItemPolicy.AbsoluteExpiration = DateTime.Now.AddSeconds(int.Parse(bearerToken.ExpiresIn));
		 cache.Add(CacheKey, bearerToken, cacheItemPolicy);
	 }

	 var gateway = new ArkenAPIGateway(new Uri(_appSettings.BaseUrl));

	 gateway.HttpClient.DefaultRequestHeaders.Add(KbxIntegrationApiResource.Authorization,
		 $"{bearerToken.TokenType} {bearerToken.AccessToken}");

	 return gateway;
}


Once you have generated the token key, you need to add this to your HTTP request to be authenticated, as per example below:

GET https://pre-service-nz.api.arken.legal/v0/nzl/Account?hashId=FadoZG9ly2TKY5j6N3ezlE HTTP/1.1
Accept: application/json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik9UUXdOalE1TnpSRk9EUTNPVFl5UWtaRk0wSTFNVGcyUmpJNU1qRTBRekUxTXpkQk9UYzBNdyJ9.eyJpc3MiOiJodHRwczovL2RldmVsb3BtZW50LWFya2VubGVnYWwuYXUuYXV0aDAuY29tLyIsInN1YiI6InBMWFhrQmJoZkVJTkkySGpRYU1Ma2puSDdqWGxiNGVvQGNsaWVudHMiLCJhdWQiOiJodHRwczovL2F1dGgtYXVuei5hcGkuYXJrZW4ubGVnYWwiLCJpYXQiOjE1Mjg2Njg0NjIsImV4cCI6MTUyODc1NDg2MiwiYXpwIjoicExYWGtCYmhmRUlOSTJIalFhTUxram5IN2pYbGI0ZW8iLCJzY29wZSI6ImNvbnN1bWVyOmFjY2VzcyBpbnRlcm5hbDphY2Nlc3MgYWxsOmFjY2VzcyIsImd0eSI6ImNsaWVudC1jcmVkZW50aWFscyJ9.0-dZ-rIlTrCTJ8ISl09gQXv32bC8PBP5gm55tkOKelUyA5szZoKkJ1jfKYcxuP5gfMei9MvTaMV9iauzEueow4N0QxVM4EpfKMHp9hjDytdTBIzSZAyCVJOmqJwTXBYS40ceRAI23IiQkmQA73dX0Z9M9Gu1rxzKF18TaU4CU8OdDV8teYRFQtPxJdsoQMKyhiYA81NvKQuc2kgYMwrVHuqQ_8QyhFqDOOdBZajbfdJTsdq6l6QNaUZHJ42yBrJ7rqvKlYTxcz7LZPQYKT19_e1_vFeIO73eunuQ8MUYfng5aPmFqzkGGLnEsY2DCL6wqjP-PDYfbk0Hk3lfbnGW-A
Host: local.service.api.arken.legal
cookie: __cfduid=d6f04a38626c8be80acf93e8e3c0b17c71525907766
accept-encoding: gzip, deflate
Connection: close