deepgram / deepgram-dotnet-sdk

.NET SDK for Deepgram's automated speech recognition APIs.
https://developers.deepgram.com
MIT License
30 stars 31 forks source link

Add { timeToLive: X } ability when generating key #319

Closed behrad-techtiq closed 2 months ago

behrad-techtiq commented 2 months ago

Can you please introduce the ability to expire key while generating it via .net SDK.

dvonthenen commented 2 months ago

Hi @behrad-techtiq

The option you are looking for should already be there https://github.com/deepgram/deepgram-dotnet-sdk/blob/main/Deepgram/Models/Manage/v1/KeySchema.cs#L44

Are you finding an issue with it?

behrad-techtiq commented 2 months ago

Hi @behrad-techtiq

The option you are looking for should already be there https://github.com/deepgram/deepgram-dotnet-sdk/blob/main/Deepgram/Models/Manage/v1/KeySchema.cs#L44

Are you finding an issue with it?

Thanks @dvonthenen for highlighting it. problem is I couldn't find any documentation how to create key in C# specially since new version separated the client there is now clear documentation how to create instance of Deepgram managed client.

and to be more specific when it comes to Key creating the only documentation mentioned it is using CURL

https://developers.deepgram.com/docs/create-additional-api-keys

although I ended up figuring it out , good to update documents

        var deepgramClient = ClientFactory.CreateManageClient(apiKey: key);
        await deepgramClient.CreateKey("dsd", new KeySchema()
        {
            Comment = "TEST",
            TimeToLiveInSeconds = 3600
        });
behrad-techtiq commented 2 months ago

One more Problem @dvonthenen

    public async Task<KeyResponse> GenerateDeepGramKey(string name)
    {
      return  await _deepgramManageClient.CreateKey("XX", new KeySchema()
        {
            Comment = name,
            TimeToLiveInSeconds = 2000,
            Scopes = new List<string>() {"usage.read", "usage.write"},
            Tags = new List<string>(){"API GENERATED"},

        });
    }

but the response ignores both time to live and scopes

      { 
  "api_key_id": "f62934c6-xxxxxxx",   "key": "1638f49axxxxxxxxxxxxxx",   "comment": "25f0eaeb-031b-4663-bbe3- 
                      d8ec36c33842__785",   
      "scopes": [], 
        "created": "2024-07-26T03:30:38.428065Z",  
       "tags": [     "API GENERATED"   ] 

      }

--

dvonthenen commented 2 months ago

If you need any references or documentation on how to use the SDK, I would take a look at the README at the root of the repo. Specifically, in the examples section: https://github.com/deepgram/deepgram-dotnet-sdk?tab=readme-ov-file#example-code

There is an example for just about every command and often times in multiple ways or configurations. For the manage API to create a new key, you can find this example referenced in the readme: https://github.com/deepgram/deepgram-dotnet-sdk/blob/main/examples/manage/keys/Program.cs#L57

dvonthenen commented 2 months ago
      { 
  "api_key_id": "f62934c6-xxxxxxx",   "key": "1638f49axxxxxxxxxxxxxx",   "comment": "25f0eaeb-031b-4663-bbe3- 
                      d8ec36c33842__785",   
      "scopes": [], 
        "created": "2024-07-26T03:30:38.428065Z",  
       "tags": [     "API GENERATED"   ] 

      }

I will take a look at the output today and see what is up with the scope and if you are suppose to get back the TTL for the key.

behrad-techtiq commented 2 months ago
      { 
  "api_key_id": "f62934c6-xxxxxxx",   "key": "1638f49axxxxxxxxxxxxxx",   "comment": "25f0eaeb-031b-4663-bbe3- 
                      d8ec36c33842__785",   
      "scopes": [], 
        "created": "2024-07-26T03:30:38.428065Z",  
       "tags": [     "API GENERATED"   ] 

      }

I will take a look at the output today and see what is up with the scope and if you are suppose to get back the TTL for the key.

any updates @dvonthenen ?

dvonthenen commented 2 months ago

It looks like the result is missing the expiration_date value which I can add. Thanks for finding that.

And I don't believe usage.read and usage.write is valid. I believe to access usage APIs, you need project:read (note the :) per the docs: https://developers.deepgram.com/reference/get-request

{"api_key_id":"XXXX","key":"XXXX","comment":"MyTestKey","scopes":["member"],"created":"2024-07-29T15:16:26.878698Z","expiration_date":"2024-07-29T16:16:26.877452668Z"}
dvonthenen commented 2 months ago

The PR was merged. We are targeting a release on Monday.