Recipients

Sending messages to authenticated users.

Recipients are identified and authenticated users that can receive private notifications. Recipients can be authenticated via the JavaScript client or by using the Rest-API.

Identifying a Recipient using the JavaScript client

Before you identify the Recipient you will need a HMAC. For HMAC generation example, let's assume that the secret key is 4RjprPVSxDUnh5GhVJeLkVGrCUmzff and the unique user id is vdmr1xmt. Here are examples on how HMAC would be generated by using PHP or JavaScript.

Before user data is passed to HMAC function, you need to sort it by keys and convert it to JSON string format. The generated HMAC also needs to be presented in hexadecimal format.

$data = [
    'id' => 'vdmr1xmt',
    'name' => 'John Doe',
    'email' => 'john.doe@example.com'
];

ksort($data);

$hmac = hash_hmac(
    'sha256',
    json_encode($data),
    '4RjprPVSxDUnh5GhVJeLkVGrCUmzff' // unique secret key, you get this from the app settings
);

Use a unique value to identify your Recipients, also you are required to send the HMAC that we generated in the previous example. You can also include additional attributes. These attributes that you send can be used in notifications.

Notific.setUser({
    id: "UNIQUE_USER_ID", // Unique identifier for current user
    hmac: "GENERATED_HMAC", // HMAC generated from user data by using secret key
    name: "John Doe",   // Current user's name
    email: "john.doe@example.com", // Current user's email
    // Additional user properties.
    // is_trial: false,
    // plan: "enterprise"
});

To log out a user from Notific, call Notific.setUser(null) without any additional information.