Skip to main content

start_token_manager

Function start_token_manager 

Source
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

§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(_)));