JSON Web Tokens (JWTs)
1
2
3
Sign the payload
// Example uses jose-jwt: https://github.com/dvsekhvalnov/jose-jwt
using System.Collections.Generic;
using System.Text;
using Jose;
namespace JwtExample
{
class Jwt
{
// An example for building a user JWT.
// accountSid/authToken - your impact.com API credentials
// userId - your unique identifier for this user
public static string BuildJwt(string accountSid, string authToken, string userId, string email, string firstName, string lastName)
{
// Build the user payload. Most fields are optional, but id and accountId are required
// and are set to the same value. See the API documentation for more fields that you
// can add to your users.
var userPayload = new Dictionary<string, object>() {
{ "id", userId }, // required
{ "accountId", userId }, // required
{ "firstName", firstName }, // optional
{ "lastName", lastName }, // optional
{ "email", email } // optional
};
// Expiry date is optional, but recommended
var expiryDate = ((DateTimeOffset)DateTime.UtcNow.Date.AddDays(7)).ToUnixTimeSeconds();
var payload = new Dictionary<string, object>() {
{ "user", userPayload },
{ "exp", expiryDate }
};
var headers = new Dictionary<string, object>() {
{ "typ", "JWT" },
{ "kid", accountSid }
};
var byteSecret = Encoding.UTF8.GetBytes(authToken);
return Jose.JWT.Encode(payload, byteSecret, JwsAlgorithm.HS256, extraHeaders: headers);
}
}
}4
Include the JWT with your calls
<script>
window.impactToken = "JWT_GOES_HERE";
</script>
<impact-embed widget="p/program-id/w/referrerWidget"></impact-embed>curl -X POST 'https://app.referralsaasquatch.com/api/v1/{tenant_alias}/open/account/{accountId}/user/{userId}' \
-H "X-SaaSquatch-User-Token: {X-SaaSquatch-User-Token}" \
-H "Content-Type: application/json" \
-d '{
"id": "john@example.com",
"accountId": "john@example.com",
"email": "john@example.com",
"firstName": "John",
"lastName": "Testerson",
"locale": "en_US",
"referralCode": "JOHNTESTERSON"
}'Last updated
