SCRAM Nexus Sync uses token based authentication to allow access for API’s.
- It uses a combination of a username, password, and pre-shared client secret.
- The username, password, and client secret are sent to a secure token server and an authentication token is returned.
- The authentication token is then passed into the header with each call to the API.
- All data is exchanged using TLS encrypted communication over SSL (port 443).
Sample code to generate access token and its use.
Token Generation:
public async Task GetAccessToken(string clientId, string clientSecret, string username, string password)
{
using (var handler = new HttpClientHandler { UseCookies = false })
using (var client = new HttpClient(handler))
{
var idAndSecret = $"{clientId}:{clientSecret}";
var encodedAuthorization = Convert.ToBase64String(Encoding.UTF8.GetBytes(idAndSecret));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", encodedAuthorization);
client.DefaultRequestHeaders.Add("Cookie", "recaptchaVerified=true");
var formValues = new StringContent($"grant_type=password&scope=openid caseIntegrationApi&username={username}&password={password}", Encoding.UTF8, "application/x-www-form-urlencoded");
var response = await client.PostAsync([Token Server URI], formValues);
var responseAsString = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
throw new HttpRequestException($"Failed to get access token from ScramNet STS. Error: {responseAsString}");
}
var tokenResponse = JsonConvert.DeserializeObject(responseAsString);
return tokenResponse;
}
}
Token Usage
HttpClient _httpClient = new HttpClient();
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", [AccessToken]);