pub async fn start_token_manager(
ep: &ApiEndpoint,
secret: &str,
source_app_id: &str,
) -> Result<Arc<TokenManager>, FinamError>Expand description
Starts a TokenManager for secret on a fresh channel to ep.
Logs in once (AuthService.Auth) and starts the background refresher. Put the returned Arc into
every FinamApi that uses this secret: one secret needs one manager.
source_app_id is sent with Auth as the application id. An empty string is allowed.
§Errors
FinamError::Config: the secret is empty or the endpoint URL is invalid.FinamError::Auth: the server returned an empty token.FinamError::Status: the server refused the secret (codeUNAUTHENTICATED) or could not be reached.
§Examples
use brokapi_finam_protocol::{ApiEndpoint, FinamError, start_token_manager};
let tokens = start_token_manager(&endpoint, secret, "my-app").await?;
assert!(!tokens.current().is_empty());
// A wrong secret is refused by the server.
let err = start_token_manager(&endpoint, "wrong-secret", "my-app").await.unwrap_err();
assert!(err.is_unauthenticated());
// An empty secret never leaves the process.
let err = start_token_manager(&endpoint, " ", "my-app").await.unwrap_err();
assert!(matches!(err, FinamError::Config(_)));