diff --git a/infisical_sdk/resources/auth.py b/infisical_sdk/resources/auth.py index c45e620..30f36b5 100644 --- a/infisical_sdk/resources/auth.py +++ b/infisical_sdk/resources/auth.py @@ -3,6 +3,7 @@ from infisical_sdk.resources.auth_methods import UniversalAuth from infisical_sdk.resources.auth_methods import OidcAuth from infisical_sdk.resources.auth_methods import TokenAuth +from infisical_sdk.resources.auth_methods import LdapAuth from typing import Callable class Auth: @@ -11,4 +12,5 @@ def __init__(self, requests: InfisicalRequests, setToken: Callable[[str], None]) self.aws_auth = AWSAuth(requests, setToken) self.universal_auth = UniversalAuth(requests, setToken) self.oidc_auth = OidcAuth(requests, setToken) - self.token_auth = TokenAuth(setToken) \ No newline at end of file + self.token_auth = TokenAuth(setToken) + self.ldap_auth = LdapAuth(requests, setToken) \ No newline at end of file diff --git a/infisical_sdk/resources/auth_methods/__init__.py b/infisical_sdk/resources/auth_methods/__init__.py index 15ef503..02aeef9 100644 --- a/infisical_sdk/resources/auth_methods/__init__.py +++ b/infisical_sdk/resources/auth_methods/__init__.py @@ -2,3 +2,4 @@ from .universal_auth import UniversalAuth from .oidc_auth import OidcAuth from .token_auth import TokenAuth +from .ldap_auth import LdapAuth diff --git a/infisical_sdk/resources/auth_methods/ldap_auth.py b/infisical_sdk/resources/auth_methods/ldap_auth.py new file mode 100644 index 0000000..9fdbf9f --- /dev/null +++ b/infisical_sdk/resources/auth_methods/ldap_auth.py @@ -0,0 +1,38 @@ +from infisical_sdk.api_types import MachineIdentityLoginResponse + +from typing import Callable +from infisical_sdk.infisical_requests import InfisicalRequests + +class LdapAuth: + def __init__(self, requests: InfisicalRequests, setToken: Callable[[str], None]): + self.requests = requests + self.setToken = setToken + + def login(self, identity_id: str, username: str, password: str) -> MachineIdentityLoginResponse: + """ + Login with LDAP Auth. + + Args: + identity_id (str): Your Machine Identity ID. + username (str): Your LDAP username. + password (str): Your LDAP password. + + Returns: + MachineIdentityLoginResponse: A response containing the access token and related information. + """ + + requestBody = { + "identityId": identity_id, + "username": username, + "password": password + } + + result = self.requests.post( + path="/api/v1/auth/ldap-auth/login", + json=requestBody, + model=MachineIdentityLoginResponse + ) + + self.setToken(result.data.accessToken) + + return result.data