semantic-kernel
semantic-kernel copied to clipboard
Can I use token from azure credential instead of api key to authenticate azure openai service backend
hi @LittleLittleCloud, the Azure OpenAI service client currently supports only API Key authentication. I believe you're looking for the Azure Active Directory authentication, which currently is not supported.
/cc @evchaki
@dluc I can use apikey for now, thanks for the answer
@dluc - Azure AD Auth is supported (via Bearer token) in AOAI: https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/managed-identity. I'd recommend reopening this one as this is a feature that should be supported. We generally recommend use of MSI over API Keys (as they are much more secure). This will be a limiting factor for adoption of SK for more security focused organizations.
Here are the REST API reference docs showing the AAD Auth support via Bearer token: https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#authentication
@LittleLittleCloud - any chance you would be able to reopen this issue?
@PlagueHO Sure
@LittleLittleCloud @PlagueHO this is now supported! See here for an example: https://github.com/microsoft/semantic-kernel/blob/main/samples/dotnet/kernel-syntax-examples/Example25_AADAuth.cs
I'll go ahead and close - please reach out if you believe there's more to do here.
Thanks for the feature request.
Awesome! Thanks @shawncal - much appreciated.
HI @shawncal the link referenced here is not found. Can you share an example link again please?
This works :
import semantic_kernel as sk
from azure.identity import DefaultAzureCredential
from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion
default_credential = DefaultAzureCredential()
token = default_credential.get_token(
"https://cognitiveservices.azure.com/.default"
)
kernel = sk.Kernel()
kernel.add_text_completion_service(
"dv",
AzureTextCompletion(
deployment_name=<your deployment name>,
endpoint=<your endpoint>
api_key=token.token,
api_version="2023-05-15",
ad_auth=True,
),
)
@vamshisiram I think this is the new link https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/KernelSyntaxExamples/Example26_AADAuth.cs