nat.data_models.authentication#

Attributes#

Classes#

AuthProviderBaseConfig

Base configuration for authentication providers.

CredentialLocation

Enum representing the location of credentials in an HTTP request.

AuthFlowType

Enum representing different types of authentication flows.

AuthenticatedContext

Represents an authenticated context for making requests.

HeaderAuthScheme

Enum representing different header authentication schemes.

HTTPMethod

Enum representing HTTP methods used in requests.

CredentialKind

Enum representing different kinds of credentials used for authentication.

_CredBase

Base class for credentials used in authentication.

HeaderCred

Represents a credential that is sent in the HTTP header.

QueryCred

Represents a credential that is sent as a query parameter in the URL.

CookieCred

Represents a credential that is sent as a cookie in the HTTP request.

BasicAuthCred

Represents credentials for HTTP Basic Authentication.

BearerTokenCred

Represents a credential for Bearer Token Authentication.

AuthResult

Represents the result of an authentication process.

Module Contents#

class AuthProviderBaseConfig(/, **data: Any)#

Bases: nat.data_models.common.TypedBaseModel, nat.data_models.common.BaseModelRegistryTag

Base configuration for authentication providers.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

AuthProviderBaseConfigT#
class CredentialLocation#

Bases: str, enum.Enum

Enum representing the location of credentials in an HTTP request.

Initialize self. See help(type(self)) for accurate signature.

HEADER = 'header'#
QUERY = 'query'#
COOKIE = 'cookie'#
BODY = 'body'#
class AuthFlowType#

Bases: str, enum.Enum

Enum representing different types of authentication flows.

Initialize self. See help(type(self)) for accurate signature.

API_KEY = 'api_key'#
OAUTH2_CLIENT_CREDENTIALS = 'oauth2_client_credentials'#
OAUTH2_AUTHORIZATION_CODE = 'oauth2_auth_code_flow'#
OAUTH2_PASSWORD = 'oauth2_password'#
OAUTH2_DEVICE_CODE = 'oauth2_device_code'#
HTTP_BASIC = 'http_basic'#
NONE = 'none'#
class AuthenticatedContext(/, **data: Any)#

Bases: pydantic.BaseModel

Represents an authenticated context for making requests.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

headers: dict[str, str] | httpx.Headers | None = None#
query_params: dict[str, str] | httpx.QueryParams | None = None#
cookies: dict[str, str] | httpx.Cookies | None = None#
body: dict[str, str] | None = None#
metadata: dict[str, Any] | None = None#
class HeaderAuthScheme#

Bases: str, enum.Enum

Enum representing different header authentication schemes.

Initialize self. See help(type(self)) for accurate signature.

BEARER = 'Bearer'#
X_API_KEY = 'X-API-Key'#
BASIC = 'Basic'#
CUSTOM = 'Custom'#
class HTTPMethod#

Bases: str, enum.Enum

Enum representing HTTP methods used in requests.

Initialize self. See help(type(self)) for accurate signature.

GET = 'GET'#
POST = 'POST'#
PUT = 'PUT'#
DELETE = 'DELETE'#
PATCH = 'PATCH'#
HEAD = 'HEAD'#
OPTIONS = 'OPTIONS'#
class CredentialKind#

Bases: str, enum.Enum

Enum representing different kinds of credentials used for authentication.

Initialize self. See help(type(self)) for accurate signature.

HEADER = 'header'#
QUERY = 'query'#
COOKIE = 'cookie'#
BASIC = 'basic_auth'#
BEARER = 'bearer_token'#
class _CredBase(/, **data: Any)#

Bases: pydantic.BaseModel

Base class for credentials used in authentication.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

kind: CredentialKind#
model_config#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class HeaderCred(/, **data: Any)#

Bases: _CredBase

Represents a credential that is sent in the HTTP header.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

kind: Literal[CredentialKind]#
name: str#
value: pydantic.SecretStr#
class QueryCred(/, **data: Any)#

Bases: _CredBase

Represents a credential that is sent as a query parameter in the URL.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

kind: Literal[CredentialKind]#
name: str#
value: pydantic.SecretStr#
class CookieCred(/, **data: Any)#

Bases: _CredBase

Represents a credential that is sent as a cookie in the HTTP request.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

kind: Literal[CredentialKind]#
name: str#
value: pydantic.SecretStr#
class BasicAuthCred(/, **data: Any)#

Bases: _CredBase

Represents credentials for HTTP Basic Authentication.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

kind: Literal[CredentialKind]#
username: pydantic.SecretStr#
password: pydantic.SecretStr#
class BearerTokenCred(/, **data: Any)#

Bases: _CredBase

Represents a credential for Bearer Token Authentication.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

kind: Literal[CredentialKind]#
token: pydantic.SecretStr#
scheme: str = 'Bearer'#
header_name: str = 'Authorization'#
Credential#
class AuthResult(/, **data: Any)#

Bases: pydantic.BaseModel

Represents the result of an authentication process.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

credentials: list[Credential] = None#
token_expires_at: datetime.datetime | None = None#
raw: dict[str, Any] = None#
model_config#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

is_expired() bool#

Checks if the authentication token has expired.

as_requests_kwargs() dict[str, Any]#

Converts the authentication credentials into a format suitable for use with the httpx library.

attach(target_kwargs: dict[str, Any]) None#

Attaches the authentication credentials to the target request kwargs.