fromDomain

suspend fun fromDomain(domain: String, network: Network, httpClient: HttpClient? = null, httpRequestHeaders: Map<String, String>? = null, clientDomainSigningDelegate: ClientDomainSigningDelegate? = null): WebAuth

Creates a WebAuth instance by discovering configuration from a domain's stellar.toml.

This is the recommended way to initialize WebAuth. It automatically fetches the stellar.toml file from the specified domain and extracts the required configuration:

  • WEB_AUTH_ENDPOINT: The authentication endpoint URL

  • SIGNING_KEY: The server's public signing key for validating challenges

The stellar.toml file is fetched from: https://{domain}/.well-known/stellar.toml

This method ensures you're using the correct, up-to-date configuration published by the service, reducing configuration errors and improving security.

Example:

// Initialize from testnet anchor
val webAuth = WebAuth.fromDomain(
domain = "testanchor.stellar.org",
network = Network.TESTNET
)

// Authenticate a user
val token = webAuth.jwtToken(accountId, signers)

Example with error handling:

try {
val webAuth = WebAuth.fromDomain("example.com", Network.PUBLIC)
// Use webAuth for authentication
} catch (e: ChallengeRequestException) {
println("Failed to load stellar.toml or missing required fields: ${e.message}")
}

Return

WebAuth instance configured from the domain's stellar.toml

Parameters

domain

The domain name (without protocol). E.g., "example.com"

network

The Stellar network (Network.PUBLIC or Network.TESTNET)

httpClient

Optional custom HTTP client for testing or proxy configuration

httpRequestHeaders

Optional custom HTTP headers to include in requests

clientDomainSigningDelegate

Optional delegate for external client domain signing

Throws

If stellar.toml is missing, invalid, or lacks required fields