Private AirOps Agents require authentication using three pieces of information:
Workspace ID
User ID (an identifier for the user in your application)
Hashed User ID
Here's how to hash the User ID using your workspace's API key on your back-end server.
require "openssl"
def user_id_hash
api_key = "YOUR_API_KEY" # your workspace token (keep safe!)
user_id = "YOUR_USER_ID"
# Convert your api key to bytes
key = api_key.encode("utf-8")
# Hash the message using HMAC-SHA256 and the key
hash = OpenSSL::HMAC.hexdigest('sha256', key, user_id)
end
import hashlib
def user_id_hash():
api_key = "YOUR_API_KEY" # your workspace token (keep safe!)
user_id = "YOUR_USER_ID"
# Convert your api key to bytes
key = bytes(api_key, 'utf-8')
# Hash the message using HMAC-SHA256 and the key
hash = hashlib.sha256(key + bytes(user_id, 'utf-8')).hexdigest()
return hash
const crypto = require('crypto');
const userIdHash = () => {
const apiKey = "YOUR_API_KEY"; // your workspace token (keep safe!)
const userId = "YOUR_USER_ID";
// Convert your api key to a buffer
const key = Buffer.from(apiKey, 'utf-8');
// Hash the message using HMAC-SHA256 and the key
const hash = crypto.createHmac('sha256', key)
.update(userId)
.digest('hex');
return hash;
}
If you need to fetch your hashed user id from a server or gather user input as variables, you may prefer not to initialize the widget automatically. Use the following: