deepgram.clients.auth.client
1# Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. 2# Use of this source code is governed by a MIT license that can be found in the LICENSE file. 3# SPDX-License-Identifier: MIT 4 5from .v1.client import AuthRESTClient as AuthRESTClientLatest 6from .v1.async_client import AsyncAuthRESTClient as AsyncAuthRESTClientLatest 7from .v1.response import GrantTokenResponse as GrantTokenResponseLatest 8 9AuthRESTClient = AuthRESTClientLatest 10AsyncAuthRESTClient = AsyncAuthRESTClientLatest 11GrantTokenResponse = GrantTokenResponseLatest
14class AuthRESTClient(AbstractSyncRestClient): 15 """ 16 A client class for handling authentication endpoints. 17 Provides method for generating a temporary JWT token. 18 """ 19 20 _logger: verboselogs.VerboseLogger 21 _config: DeepgramClientOptions 22 _endpoint: str 23 24 def __init__(self, config: DeepgramClientOptions): 25 self._logger = verboselogs.VerboseLogger(__name__) 26 self._logger.addHandler(logging.StreamHandler()) 27 self._logger.setLevel(config.verbose) 28 self._config = config 29 self._endpoint = "v1/auth/grant" 30 super().__init__(config) 31 32 def grant_token(self): 33 """ 34 Generates a temporary JWT with a 30 second TTL. 35 36 Returns: 37 GrantTokenResponse: An object containing the authentication token and its expiration time. 38 39 Raises: 40 DeepgramTypeError: Raised for known API errors. 41 """ 42 self._logger.debug("AuthRestClient.grant_token ENTER") 43 44 url = f"{self._config.url}/{self._endpoint}" 45 self._logger.info("url: %s", url) 46 result = self.post(url, headers={"Authorization": f"Token {self._config.api_key}"}) 47 self._logger.info("json: %s", result) 48 res = GrantTokenResponse.from_json(result) 49 self._logger.verbose("result: %s", res) 50 self._logger.notice("grant_token succeeded") 51 self._logger.debug("AuthRestClient.grant_token LEAVE") 52 return res
A client class for handling authentication endpoints. Provides method for generating a temporary JWT token.
AuthRESTClient(config: deepgram.options.DeepgramClientOptions)
def
grant_token(self):
32 def grant_token(self): 33 """ 34 Generates a temporary JWT with a 30 second TTL. 35 36 Returns: 37 GrantTokenResponse: An object containing the authentication token and its expiration time. 38 39 Raises: 40 DeepgramTypeError: Raised for known API errors. 41 """ 42 self._logger.debug("AuthRestClient.grant_token ENTER") 43 44 url = f"{self._config.url}/{self._endpoint}" 45 self._logger.info("url: %s", url) 46 result = self.post(url, headers={"Authorization": f"Token {self._config.api_key}"}) 47 self._logger.info("json: %s", result) 48 res = GrantTokenResponse.from_json(result) 49 self._logger.verbose("result: %s", res) 50 self._logger.notice("grant_token succeeded") 51 self._logger.debug("AuthRestClient.grant_token LEAVE") 52 return res
Generates a temporary JWT with a 30 second TTL.
Returns: GrantTokenResponse: An object containing the authentication token and its expiration time.
Raises: DeepgramTypeError: Raised for known API errors.
14class AsyncAuthRESTClient(AbstractAsyncRestClient): 15 """ 16 A client class for handling authentication endpoints. 17 Provides method for generating a temporary JWT token. 18 """ 19 20 _logger: verboselogs.VerboseLogger 21 _config: DeepgramClientOptions 22 _endpoint: str 23 24 def __init__(self, config: DeepgramClientOptions): 25 self._logger = verboselogs.VerboseLogger(__name__) 26 self._logger.addHandler(logging.StreamHandler()) 27 self._logger.setLevel(config.verbose) 28 self._config = config 29 self._endpoint = "v1/auth/grant" 30 super().__init__(config) 31 32 async def grant_token(self): 33 """ 34 Generates a temporary JWT with a 30 second TTL. 35 36 Returns: 37 GrantTokenResponse: An object containing the authentication token and its expiration time. 38 39 Raises: 40 DeepgramTypeError: Raised for known API errors. 41 """ 42 self._logger.debug("AuthRestClient.grant_token ENTER") 43 44 url = f"{self._config.url}/{self._endpoint}" 45 self._logger.info("url: %s", url) 46 result = await self.post(url, headers={"Authorization": f"Token {self._config.api_key}"}) 47 self._logger.info("json: %s", result) 48 res = GrantTokenResponse.from_json(result) 49 self._logger.verbose("result: %s", res) 50 self._logger.notice("grant_token succeeded") 51 self._logger.debug("AuthRestClient.grant_token LEAVE") 52 return res
A client class for handling authentication endpoints. Provides method for generating a temporary JWT token.
AsyncAuthRESTClient(config: deepgram.options.DeepgramClientOptions)
async def
grant_token(self):
32 async def grant_token(self): 33 """ 34 Generates a temporary JWT with a 30 second TTL. 35 36 Returns: 37 GrantTokenResponse: An object containing the authentication token and its expiration time. 38 39 Raises: 40 DeepgramTypeError: Raised for known API errors. 41 """ 42 self._logger.debug("AuthRestClient.grant_token ENTER") 43 44 url = f"{self._config.url}/{self._endpoint}" 45 self._logger.info("url: %s", url) 46 result = await self.post(url, headers={"Authorization": f"Token {self._config.api_key}"}) 47 self._logger.info("json: %s", result) 48 res = GrantTokenResponse.from_json(result) 49 self._logger.verbose("result: %s", res) 50 self._logger.notice("grant_token succeeded") 51 self._logger.debug("AuthRestClient.grant_token LEAVE") 52 return res
Generates a temporary JWT with a 30 second TTL.
Returns: GrantTokenResponse: An object containing the authentication token and its expiration time.
Raises: DeepgramTypeError: Raised for known API errors.
13@dataclass 14class GrantTokenResponse(BaseResponse): 15 """ 16 The response object for the authentication grant token endpoint. 17 """ 18 access_token: str = field( 19 metadata=dataclass_config(field_name='access_token'), 20 default="", 21 ) 22 expires_in: int = field( 23 metadata=dataclass_config(field_name='expires_in'), 24 default=30, 25 )
The response object for the authentication grant token endpoint.