Client identities and protocols
Create a client identity, load it back, and see which protocols it can use.
Part of SDK Functions. Every call below is shown in each language that has it.
Create A Client Identity
Section titled “Create A Client Identity”Create an identity when a browser, service, voice client, device, or agent needs to connect to one hub.
result = api.create_client_identity( "hub-id", name="checkout-kiosk", preferred_protocols=("wss", "https"),)
identity = result.identityconst result = await api.createClientIdentity("hub-id", { name: "checkout-kiosk", preferredProtocols: ["wss", "https"],});
const identity = result.identity;result, err := api.CreateClientIdentityForHubID(ctx, "hub-id", thalovant.BootstrapIdentityOptions{ Name: "checkout-kiosk", PreferredProtocols: []thalovant.HubProtocol{thalovant.ProtocolWSS, thalovant.ProtocolHTTPS},})if err != nil { log.Fatal(err)}
identity := result.Identitylet result = api .create_client_identity_for_hub_id( "hub-id", BootstrapIdentityOptions { name: "checkout-kiosk".into(), preferred_protocols: vec![HubProtocol::Wss, HubProtocol::Https], ..Default::default() }, ) .await?;
let identity = result.identity.clone();val result = api.createClientIdentity( "hub-id", CreateClientIdentityOptions(name = "checkout-kiosk"),)
val identity = result.identitylet result = try await api.createClientIdentity( hubId: "hub-id", options: CreateClientIdentityOptions(name: "checkout-kiosk"))
let identity = result.identityvar result = await api.CreateClientIdentityAsync( "hub-id", new CreateClientIdentityOptions("checkout-kiosk"));
var identity = result.Identity;Every SDK also accepts an active option on creation, and it defaults to true. Pass false to provision the client disabled, so it cannot connect until you activate it with a client update.
Load Identity Material
Section titled “Load Identity Material”Use config or a downloaded identity file when the client already exists.
On Linux and macOS, protect local config.yaml and _identity.json files with owner-only permissions before loading them:
chmod 600 ~/.config/thalovant/config.yamlchmod 600 _identity.jsonfrom thalovant import ThalovantClient, ThalovantIdentity
identity = ThalovantIdentity.from_config(profile="prod")same_identity = ThalovantIdentity.from_file("_identity.json")
client_from_config = ThalovantClient.from_config(profile="prod", protocol="wss")client_from_file = ThalovantClient.from_identity_file("_identity.json")client_from_env = ThalovantClient.from_env()const identity = await ThalovantIdentity.fromConfig({ profile: "prod" });const sameIdentity = await ThalovantIdentity.fromFile("_identity.json");
const clientFromConfig = await ThalovantClient.fromConfig({ profile: "prod", protocol: "wss" });const clientFromFile = await ThalovantClient.fromIdentityFile("_identity.json");const clientFromEnv = ThalovantClient.fromEnv();identity, err := thalovant.IdentityFromConfig("", "prod")if err != nil { log.Fatal(err)}
sameIdentity, err := thalovant.IdentityFromFile("_identity.json")if err != nil { log.Fatal(err)}
clientFromConfig, err := thalovant.NewClientFromConfig("", "prod")clientFromFile, err := thalovant.NewClientFromFile("_identity.json")clientFromEnv, err := thalovant.NewClientFromEnv()use thalovant::{Client, Identity};
let identity = Identity::from_config(Some("prod"))?;let same_identity = Identity::from_file("_identity.json")?;
let client_from_config = Client::from_config(Some("prod"))?;let client_from_file = Client::from_file("_identity.json")?;let client_from_env = Client::from_env()?;Inspect Protocols
Section titled “Inspect Protocols”Use protocol helpers before forcing WSS, HTTPS, or MQTT.
print(identity.enabled_protocols())print(identity.endpoint_for("wss"))print(identity.endpoint_for("https"))print(identity.endpoint_for("mqtt"))print(identity.supports_protocol("wss"))
if identity.mqtt: print(identity.mqtt.endpoint)console.log(identity.enabledProtocols());console.log(identity.endpointFor("wss"));console.log(identity.endpointFor("https"));console.log(identity.endpointFor("mqtt"));console.log(identity.supportsProtocol("wss"));
if (identity.mqtt) { console.log(identity.mqtt.endpoint);}fmt.Println(identity.EnabledProtocols())fmt.Println(identity.EndpointFor(thalovant.ProtocolWSS))fmt.Println(identity.EndpointFor(thalovant.ProtocolHTTPS))fmt.Println(identity.EndpointFor(thalovant.ProtocolMQTT))fmt.Println(identity.SupportsProtocol(thalovant.ProtocolWSS))
if identity.MQTT != nil { fmt.Println(identity.MQTT.Endpoint)}println!("{:?}", identity.enabled_protocols());println!("{:?}", identity.endpoint_for(HubProtocol::Wss));println!("{:?}", identity.endpoint_for(HubProtocol::Https));println!("{:?}", identity.endpoint_for(HubProtocol::Mqtt));println!("{}", identity.supports_protocol(HubProtocol::Wss));
if let Some(mqtt) = &identity.mqtt { println!("{}", mqtt.endpoint);}