class CatalogTokenProvider
Fetches and keeps the catalog access token.
Strategies, selected by CatalogCredential#auth_method: none -> no Authorization header bearer_static -> the stored secret IS the Bearer token oauth2_client_credentials -> POST {endpoint}{token_path}, grant client_credentials (Polaris) oauth2_token_exchange -> RFC 8693 at an EXTERNAL token server (Dremio: a PAT is the subject token; the catalog at :8181 and the token server at :9047 differ)
Derived tokens are cached with a safety margin before expiry and NEVER persisted - only the encrypted secret is. A stale cached token surfacing as HTTP 401 mid-sync is handled by refresh!.
Constants
- DEFAULT_EXCHANGE_CLIENT_ID
- DREMIO_PAT_TOKEN_TYPE
- EXPIRY_MARGIN
Public Class Methods
# File app/services/catalog_token_provider.rb, line 27 def initialize(catalog, transport: HttpTransport.new) @catalog = catalog @credential = catalog.catalog_credential @transport = transport end
Creates the token provider for a catalog with an injectable transport.
@param catalog [Catalog] the catalog to authenticate against @param transport [HttpTransport] the HTTP transport to use
Public Instance Methods
Source
# File app/services/catalog_token_provider.rb, line 34 def headers return {} if @credential.nil? || @credential.none? return { "Authorization" => "Bearer #{@credential.secret}" } if @credential.auth_method == "bearer_static" { "Authorization" => "Bearer #{access_token}" } end
Returns the ready-to-send authentication headers.
Source
# File app/services/catalog_token_provider.rb, line 45 def refresh! Rails.cache.delete(cache_key) if @credential.present? end
Drops the cached derived token so the next headers performs a fresh exchange. Used when the catalog answers 401 to an otherwise valid request: for token-exchange catalogs that means the short-lived token expired mid-sync - a refresh fixes it, retrying with the same PAT failure would not.