Cosmos_lwt.Databasesmodule type Auth_key = Cosmos.Databases_intf.Auth_keymodule Credential : sig ... endmodule type Credentials = Cosmos.Databases_intf.Credentialsmodule Response_headers : sig ... endtype batch_validation_error = Cosmos.Databases_core.batch_validation_error = type cosmos_error = Cosmos.Databases_core.Cosmos_error.t = | Timeout_error| Connection_error| Http_error of string| Azure_error of int * Response_headers.tval string_of_cosmos_error : cosmos_error -> stringHuman-readable description of a cosmos_error.
module type S = Database_intf.Smodule Database_as (C : Credentials) : SDatabase_as connects with an arbitrary credential, e.g. a resource token minted through Permission. Master-key-only operations (list_databases, User, Permission, Offer) fail with Azure_error (401 | 403, _) under a resource token.
val credentials_of_token : endpoint:string -> string -> (module Credentials)credentials_of_token ~endpoint token wraps a permission's _token as credentials suitable for Database_as.
val credentials_of_token_provider :
endpoint:string ->
(unit -> string) ->
(module Credentials)credentials_of_token_provider ~endpoint provider calls provider for every request, so callers can refresh expiring resource tokens.
val credentials_of_aad_token :
endpoint:string ->
string ->
(module Credentials)credentials_of_aad_token ~endpoint token wraps a Microsoft Entra ID access token (e.g. az account get-access-token --resource https://cosmos.azure.com) as credentials suitable for Database_as. Unlike a resource token, an Entra token authorizes every operation, including list_databases, User, Permission and Offer.
val credentials_of_aad_token_provider :
endpoint:string ->
(unit -> string) ->
(module Credentials)credentials_of_aad_token_provider ~endpoint provider calls provider for every request, so callers running their own refresh loop (managed identity, token broker) always supply a fresh Entra access token.
module type Aad = Cosmos.Databases_intf.Aadmodule type Aad_client = Cosmos.Databases_intf.Aad_clientmodule Database_aad (A : Aad) : SDatabase_aad connects with SDK-managed Microsoft Entra ID client credentials. The first request acquires a token from https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token; the token is cached and refreshed before expiry. The service principal needs a data-plane role assignment (e.g. Cosmos DB Built-in Data Contributor); control-plane roles do not apply.
val aad_client :
?scope:string ->
?authority_host:string ->
?now:(unit -> float) ->
endpoint:string ->
tenant_id:string ->
client_id:string ->
client_secret:string ->
unit ->
(module Aad_client)aad_client builds a full Cosmos.Databases_intf.Aad_client module for sovereign clouds, a custom scope, or an injected clock; Database_aad covers the common case.