github.com/anthropics/anthropic-sdk-go@v1.70.1/internal/auth/types.go (about)

     1  package auth
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  	"time"
     7  )
     8  
     9  // AccessToken represents an access token with an optional expiry time.
    10  type AccessToken struct {
    11  	Token     string
    12  	ExpiresAt *time.Time // nil means no expiry (cache forever)
    13  }
    14  
    15  // TokenProvider fetches a fresh [AccessToken], potentially performing network calls.
    16  // The handler parameter is the resolved HTTP transport from [requestconfig.RequestConfig]
    17  // (CustomHTTPDoer ?? HTTPClient).
    18  //
    19  // Implementations must be safe for concurrent use because [TokenCache] may
    20  // invoke the provider from a background goroutine while another call is
    21  // in-flight on the main request path.
    22  type TokenProvider func(ctx context.Context, baseURL string, handler func(*http.Request) (*http.Response, error)) (*AccessToken, error)
    23  
    24  // IdentityTokenProvider provides a JWT identity token for federation.
    25  type IdentityTokenProvider interface {
    26  	GetIdentityToken(ctx context.Context) (string, error)
    27  }
    28  
    29  // CredentialsResult bundles a [TokenProvider] with config-level metadata that
    30  // needs to be propagated to the client (e.g. base_url, workspace_id).
    31  //
    32  // OrganizationID is intentionally absent: the server exposes the caller's
    33  // organization only as the anthropic-organization-id *response* header, not
    34  // as a request header, so there is no way for the SDK to act on a
    35  // config-level organization ID today.
    36  type CredentialsResult struct {
    37  	Provider    TokenProvider
    38  	BaseURL     string // from config file; empty if not set
    39  	WorkspaceID string
    40  }