alexrudall / ruby-openai

OpenAI API + Ruby! 🤖❤️ NEW: Assistant Vector Stores
MIT License
2.61k stars 302 forks source link

Add Azure AD token provider #439

Open simoleone opened 3 months ago

simoleone commented 3 months ago

The main goal of this change is to provide a way to get dynamic auth tokens into the client. The most common use-case for this is with Azure, when the token may be for a federated identity obtained using OIDC, which needs to be refreshed periodically. Another use-case for it is development scenarios against Azure when you're authenticated as yourself instead of using the static access token for the REST endpoint. In that case you might dynamically obtain/refresh a valid auth token by shelling out to az account get-access-token.

Because these kinds of tokens have relatively short expirations, they need to be refreshed, so we accept any proc-like object and call it upon every http call to get the current token. Implementors can cache this if they wish.

I also moved some configuration validation into the client. Because the client merges key-by-key, we have to ensure we re-validate it after this merge has occurred.

I made a small change to the way configuration is merged. Previously, passing a nil value would have the same behavior as not passing a key at all, which is problematic if you explicitly want to set a certain key from the global config to nil. Now, all provided keys are set, including nil.

All Submissions:

deepracercve commented 2 months ago

It'd be great to include this. Given some policy limitations on our side - a token provider might be the only way to go.