kontent-ai / delivery-sdk-net

Kontent.ai Delivery .NET SDK
https://www.nuget.org/packages/Kontent.Ai.Delivery
MIT License
32 stars 41 forks source link

Some API keys not passing the SDK validation #348

Closed pokornyd closed 1 year ago

pokornyd commented 2 years ago

Brief bug description

API keys in Kontent.ai are JWTs. As explained in JWT docs, individual parts are encoded as base64url. According to the specification, base64url can contain dashes (-) and underlines (_). SDK uses the following regex to validate API keys:

new Regex(@"[A-Za-z0-9+/]+\.[A-Za-z0-9+/]+\.[A-Za-z0-9+/]+", RegexOptions.Compiled)

The above regex will not pass for API keys, which contain either dash or underline right next to the dot which separates individual parts of the JWT, despite such API keys being valid.

Repro steps

  1. Get an API key and adjust it according to the description
  2. Pass the API key to UsePreviewApi() method during client instantiation
  3. See error

Expected behavior

The client should be instantiated properly.

Test environment

Tested on version 16.0.0, which uses the same validation regex as the latest (17.0.0)