Authentication

OAuth2 Authentication

Instead of HTTP Basic Authentication, you may use OAuth2 to authenticate to the EZ Texting API.

Create a Token

First you must create a token:

POST https://a.eztexting.com/v1/tokens/create
{
  "appKey": "username",
  "appSecret": "password"
}

You should get the following in return:

200 OK
{
  "accessToken":"1ede080e0c013c03ad0fedc3bcee3c09",
  "refreshToken":"d18a92f15a1ffd76ef598c0ee1597a0",
  "expiresInSeconds":5400
}

Using a Token

Call any API. Include the following in the header:

Authorization: Bearer <accessToken>

For example,

Authorization: Bearer 1ede080e0c013c03ad0fedc3bcee3c09

If the Token is still valid, the API call will execute as intended.

If the Token is expired, you will get a 401 response code and will need to refresh the token. Refresh tokens last for 60 days.

Refreshing a Token

Request example:

POST https://a.eztexting.com/v1/tokens/refresh
{
  "refreshToken": "d18a92f15a1ffd76ef598c0ee1597a0"
}

Response example:

200 OK
{
  "accessToken":"001b11ef6d767e0b86a7f40dff585851",
  "refreshToken":"5b57e5a49cea506607ff4451a1bf8eba",
  "expiresInSeconds":5400
}

You can now use the new accessToken to make API calls until it expires, and the new refreshToken to again generate a fresh accessToken and refreshToken pair. You can repeat the refresh token process as many times as needed.

Immediately Revoking Both Access Token and Refresh Token

Request example

POST https://a.eztexting.com/v1/tokens/revoke
{
  "token": "5b57e5a49cea506607ff4451a1bf8eba",
  "type": "REFRESH_TOKEN". // or ACCESS_TOKEN
}

Response example

200 OK

HTTP Basic Authentication

The EZ Texting API supports either HTTP Basic Authentication or OAuth2 Bearer Token to verify the user of an endpoint.

To authenticate to the EZ Texting API, you will use the same username/password pair you use to sign in to the user interface. To use HTTP Basic Authentication, an Authorization header must be sent.

Example of credentials to authenticate to the API:

Username: [email protected]
Password: c2d77eec4aa3e224

The header that the user sends will look like this:

Authorization: Basic YTYzNDNjYzRlZGQ2OmMyZDc3ZWVjNGFhM2UyMjQ=

NOTE: Authentication credentials should be base64 encoded.

That is all that is needed to authenticate to the EZ Texting API. Here are a few examples to get you started.

C#

public void SetBasicAuthHeader(WebRequest req, String userName, String userPassword)
{
	string authInfo = userName + ":" + userPassword;
	authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
	req.Headers["Authorization"] = "Basic " + authInfo;
}

Java

HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet("https://a.eztexting.com/v1/contacts/phoneNumber");
String authHeader = "Basic " + new BASE64Encoder().encode(username + ":" + password);
request.addHeader(HttpHeaders.AUTHORIZATION, authHeader);
HttpResponse response = client.execute(request);

JavaScript, using jQuery

<script type="text/javascript"> 
function make_base_auth(username, password) 
{ var tok = username + ':' + password; var hash = btoa(tok); return "Basic " + hash; } 
$('#cfTest').click(function(){ 
	$.ajax({ 
		type: "GET", 
		dataType: "xml", 
		beforeSend: function (xhr) 
		{ xhr.setRequestHeader('Authorization', make_base_auth('YourUserName', 'YourPassword')); } 
		, 
		url: "https://a.eztexting.com/v1/contacts/phoneNumber", 
		success: function(data) 
		{ alert(data); } 
	}); 
}); 
</script>

PHP, using cURL

$authentication = 'Authorization: Basic '.base64_encode("$username:$password");
$http = curl_init($url);
curl_setopt($http, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($http, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($http, CURLOPT_RETURNTRANSFER, true);
curl_setopt($http, CURLOPT_URL, $url);
curl_setopt($http, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($http, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $authentication));

What’s Next