Rust

auth

Module

How the client proves who it is in its CONNECT.

Contents

1 submodule, and what the module defines itself.

use utopia_nats::auth::NoAuth;
Rust
pub struct NoAuth

No credentials.

use utopia_nats::auth::TokenAuth;
Rust
pub struct TokenAuth

A token: {"auth_token": token}.

use utopia_nats::auth::UserPassAuth;
Rust
pub struct UserPassAuth

A user and password: {"user": user, "pass": pass}.

use utopia_nats::auth::Authenticator;
Rust
pub trait Authenticator: Send + Sync

An authentication method: the fields to merge into CONNECT, given the server's nonce (for challenge-response methods).

Rust
pub type Fields = Map<String, Value>

Fields an authentication method adds to the CONNECT payload.

auth::nkey

Own page

NKey (Ed25519 challenge-response) and JWT credentials files.

use utopia_nats::auth::nkey::CredentialsAuth;
Rust
pub struct CredentialsAuth

A user JWT and NKey seed from a .creds file: {"jwt", "nkey", "sig"}.

use utopia_nats::auth::nkey::NKeyAuth;
Rust
pub struct NKeyAuth

Signs the server's nonce with an NKey seed: {"nkey": public key, "sig": base32 signature}.

Rust
use utopia_nats::auth::{Authenticator, NKeyAuth};

// A user seed (base32 of the seed prefix, 32 key bytes and a CRC).
let seed = "SUAKKTOKDASTBOY5NUJSZXWWEN5S5WI6H5ZB7SYZOELUJFGWJE6J2XGBOY";
let auth = NKeyAuth::new("", seed);
let fields = auth.authenticate(Some("nonce"))?;
assert_eq!(fields["nkey"], auth.public_key()?.as_str());
assert!(auth.public_key()?.starts_with('U'));