-- SPDX-FileCopyrightText: 2026 Alexandra de Wit
--
-- SPDX-License-Identifier: MIT

-- | Cargo tokens use the complete Authorization value without a scheme prefix.
module Ecluse.Core.Registry.Cargo.Credential (cargoCredential) where

import Network.HTTP.Types.Header (hAuthorization)

import Ecluse.Core.Registry.Request (AuthMechanism (AuthRawKey), CredentialMapping, bareAuthorization, credentialMapping, renderAuthMechanism)

-- | Preserve native token spelling when a caller retries through a credential provider.
cargoCredential :: CredentialMapping
cargoCredential :: CredentialMapping
cargoCredential = (RequestHeaders -> Maybe ClientCredential)
-> HeaderName
-> (ClientCredential -> ByteString)
-> CredentialMapping
credentialMapping RequestHeaders -> Maybe ClientCredential
bareAuthorization HeaderName
hAuthorization (AuthMechanism -> ClientCredential -> ByteString
renderAuthMechanism AuthMechanism
AuthRawKey)