Skip to content

Latest commit

 

History

History
 
 

authorization

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Authorization

The Authorization class is defined in authorization.h at liboai::Authorization. This class is responsible for sharing all set authorization information with all component classes in liboai.

All authorization information should be set prior to the calling of any component methods such as Images, Embeddings, and so on. Failure to do so will result in a liboai::OpenAIException due to authorization failure on OpenAI's end.


Methods

This document covers the method(s) located in authorization.h. You can find their function signature(s) below.

Get Authorizer

Returns a reference to the liboai::Authorization singleton shared among all components.

static Authorization& Authorizer() noexcept;

Set API Key

Sets the API key to use in subsequent component calls.

bool SetKey(std::string_view key) noexcept;

Set Azure API Key

Sets the Azure API key to use in subsequent component calls.

bool SetAzureKey(std::string_view key) noexcept;

Set Active Directory Azure API Key

Sets the Active Directory Azure API key to use in subsequent component calls.

bool SetAzureKeyAD(std::string_view key) noexcept;

Set API Key (File)

Sets the API key to use in subsequent component calls from data found in file at path.

bool SetKeyFile(const std::filesystem::path& path) noexcept;

Set Azure API Key (File)

Sets the Azure API key to use in subsequent component calls from data found in file at path.

bool SetAzureKeyFile(const std::filesystem::path& path) noexcept;

Set Active Directory Azure API Key (File)

Sets the Active Directory Azure API key to use in subsequent component calls from data found in file at path.

bool SetAzureKeyFileAD(const std::filesystem::path& path) noexcept;

Set API Key (Environment Variable)

Sets the API key to use in subsequent component calls from an environment variable.

bool SetKeyEnv(std::string_view var) noexcept;

Set Azure API Key (Environment Variable)

Sets the Azure API key to use in subsequent component calls from an environment variable.

bool SetAzureKeyEnv(std::string_view var) noexcept;

Set Active Directory Azure API Key (Environment Variable)

Sets the Active Directory Azure API key to use in subsequent component calls from an environment variable.

bool SetAzureKeyEnvAD(std::string_view var) noexcept;

Set Organization ID

Sets the organization ID to send in subsequent component calls.

bool SetOrganization(std::string_view org) noexcept;

Set Organization ID (File)

Sets the organization ID to send in subsequent component calls from data found in file at path.

bool SetOrganizationFile(const std::filesystem::path& path) noexcept;

Set Organization ID (Environment Variable)

Sets the organization ID to send in subsequent component calls from an environment variable.

bool SetOrganizationEnv(std::string_view var) noexcept;

Set Proxies

Sets the proxy, or proxies, to use in subsequent component calls.

void SetProxies(const std::initializer_list<std::pair<const std::string, std::string>>& hosts) noexcept;
void SetProxies(std::initializer_list<std::pair<const std::string, std::string>>&& hosts) noexcept;
void SetProxies(const std::map<std::string, std::string>& hosts) noexcept;
void SetProxies(std::map<std::string, std::string>&& hosts) noexcept;

Set Proxy Authentication

Sets the username and password to use when using a certain proxy protocol.

void SetProxyAuth(const std::map<std::string, netimpl::components::EncodedAuthentication>& proto_up) noexcept;

Set Timeout

Sets the timeout in milliseconds for the library to use in component calls.

void SetMaxTimeout(int32_t ms) noexcept

Get Key

Returns the currently set API key.

constexpr const std::string& GetKey() const noexcept;

Get Organization ID

Returns the currently set organization ID.

constexpr const std::string& GetOrganization() const noexcept;

Get Proxies

Returns the currently set proxies.

netimpl::components::Proxies GetProxies() const noexcept;

Get Proxy Authentication

Returns the currently set proxy authentication information.

netimpl::components::ProxyAuthentication GetProxyAuth() const noexcept;

Get Timeout

Returns the currently set timeout.

netimpl::components::Timeout GetMaxTimeout() const noexcept;

Get Authorization Headers

Returns the currently set authorization headers based on set information.

constexpr const netimpl::components::Header& GetAuthorizationHeaders() const noexcept;

Get Azure Authorization Headers

Returns the currently set Azure authorization headers based on set information.

constexpr const netimpl::components::Header& GetAzureAuthorizationHeaders() const noexcept;

Example Usage

For example usage of the above function(s), please refer to the examples folder.