Skip to content

Commit 32d5fa7

Browse files
committed
Expired api keys should not be allowed, prevent infinite GetToken loop´
1 parent aa587d3 commit 32d5fa7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Anthropic.Foundry/AnthropicFoundryIdentityTokenCredentials.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public AnthropicFoundryIdentityTokenCredentials(TokenCredential tokenCredential,
3535
[Obsolete("This constructor is deprecated. Please use the constructor that takes a TokenCredential instead.")]
3636
public AnthropicFoundryIdentityTokenCredentials(AccessToken apiKey, string resourceName) : this(DelegatedTokenCredential.Create((_, _) => apiKey), resourceName)
3737
{
38-
if (apiKey.Equals(default) || string.IsNullOrWhiteSpace(apiKey.Token))
38+
if (apiKey.Equals(default) || string.IsNullOrWhiteSpace(apiKey.Token) || apiKey.ExpiresOn <= DateTimeOffset.Now)
3939
{
4040
throw new ArgumentNullException(
4141
nameof(apiKey),
42-
"Invalid/Empty api key struct is not valid"
42+
"Invalid/Empty or already expired api key struct is not valid"
4343
);
4444
}
4545
}

0 commit comments

Comments
 (0)