pub struct Auth { /* private fields */ }Expand description
The configured authentication flow. Build one with Auth::developer_token,
Auth::client_credentials, or Auth::oauth, then pass it to
Client::new.
Implementations§
Source§impl Auth
impl Auth
Sourcepub fn developer_token(token: impl Into<String>) -> Auth
pub fn developer_token(token: impl Into<String>) -> Auth
The simplest flow: a fixed access token from the Box developer console.
Sourcepub fn client_credentials(config: CcgConfig) -> Auth
pub fn client_credentials(config: CcgConfig) -> Auth
Client Credentials Grant: server-to-server auth with no signing key. Set
exactly one subject on the config — enterprise_id for the service
account, or user_id to act as a managed user.
Sourcepub fn jwt(config: JwtConfig) -> Result<Auth, Error>
pub fn jwt(config: JwtConfig) -> Result<Auth, Error>
JWT server auth: sign a short-lived RSA assertion (from the app’s
box_config.json) and exchange it for an access token. Set exactly one
subject on the config — enterprise_id or user_id.
Fallible: the RSA private key is parsed (and if needed decrypted) up front, so a bad key fails here rather than on the first request.
Sourcepub fn oauth(config: OAuthConfig, refresh_token: impl Into<String>) -> Auth
pub fn oauth(config: OAuthConfig, refresh_token: impl Into<String>) -> Auth
Resume the OAuth 2.0 authorization-code flow from a previously stored refresh token, exchanging it for access tokens as needed. Box rotates the refresh token on each exchange, so the newest one is retained.
The rotated token is held in memory only; use Auth::oauth_with_store
to persist each rotation durably across restarts.
Sourcepub fn oauth_with_store(
config: OAuthConfig,
refresh_token: impl Into<String>,
store: Arc<dyn RefreshTokenStore>,
) -> Auth
pub fn oauth_with_store( config: OAuthConfig, refresh_token: impl Into<String>, store: Arc<dyn RefreshTokenStore>, ) -> Auth
Like Auth::oauth, but persists each rotated refresh token through a
RefreshTokenStore before returning — so an app restart reloads the
live token instead of a refresh token Box has already invalidated.
Sourcepub fn custom(source: Arc<dyn TokenSource>) -> Auth
pub fn custom(source: Arc<dyn TokenSource>) -> Auth
Build an Auth from a custom TokenSource — for callers that need
to own token acquisition and refresh outside the built-in flows (e.g.
an engine-owned token cache with proactive refresh and per-identity
fan-out) instead of one of the flows above.