|
| 1 | +// Copyright 2024 Deepgram .NET 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 | + |
| 5 | +using Deepgram.Models.Authenticate.v1; |
| 6 | +using Deepgram.Models.Auth.v1; |
| 7 | +using Deepgram.Clients.Interfaces.v1; |
| 8 | +using Deepgram.Abstractions.v1; |
| 9 | + |
| 10 | +namespace Deepgram.Clients.Auth.v1; |
| 11 | + |
| 12 | +/// <summary> |
| 13 | +/// Implements version 1 of the Models Client. |
| 14 | +/// </summary> |
| 15 | +/// <param name="apiKey">Required DeepgramApiKey</param> |
| 16 | +/// <param name="deepgramClientOptions"><see cref="DeepgramHttpClientOptions"/> for HttpClient Configuration</param> |
| 17 | +public class Client(string? apiKey = null, IDeepgramClientOptions? deepgramClientOptions = null, string? httpId = null) |
| 18 | + : AbstractRestClient(apiKey, deepgramClientOptions, httpId), IAuthClient |
| 19 | +{ |
| 20 | + /// <summary> |
| 21 | + /// Gets a temporary JWT for the Deepgram API. |
| 22 | + /// </summary> |
| 23 | + /// <returns><see cref="GrantTokenResponse"/></returns> |
| 24 | + public async Task<GrantTokenResponse> GrantToken(CancellationTokenSource? cancellationToken = default, |
| 25 | + Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null) |
| 26 | + { |
| 27 | + Log.Verbose("AuthClient.GrantToken", "ENTER"); |
| 28 | + |
| 29 | + var uri = GetUri(_options, $"auth/{UriSegments.GRANTTOKEN}"); |
| 30 | + var result = await PostAsync<object, GrantTokenResponse>(uri, null, cancellationToken, addons, headers); |
| 31 | + |
| 32 | + Log.Information("GrantToken", $"{uri} Succeeded"); |
| 33 | + Log.Debug("GrantToken", $"result: {result}"); |
| 34 | + Log.Verbose("AuthClient.GrantToken", "LEAVE"); |
| 35 | + |
| 36 | + return result; |
| 37 | + } |
| 38 | +} |
0 commit comments