Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.17k stars 4.54k forks source link

[QUERY] Integrating Azure AD Token Authorization in .NET by passing authorization token #44805

Closed shouryashashank closed 4 days ago

shouryashashank commented 1 week ago

Library name and version

Azure.AI.OpenAI --version 2.0.0-beta.2

Query/Question

Hello,

I am currently using Azure AD token to authorize the client in Python and it's working fine with the Python library. Here is the relevant code snippet from the Python library:

image

https://github.com/openai/openai-python/blob/6316b7c0f182877e578a3dbed2fd129b63538af5/src/openai/lib/azure.py#L291

However, I am facing difficulties when trying to implement the same in .NET. Currently, my only option is to create my own HTTP client and make REST calls and passing request header

Authorization :  Bearer ****

It would be great if you could provide some guidance or point me to the relevant documentation or examples. Any help would be greatly appreciated.

Thank you.

Environment

Windows 11 dotnet 6

github-actions[bot] commented 1 week ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jpalvarezl @ralph-msft @trrwilson.

jsquire commented 1 week ago

@shouryashashank : The Azure SDK clients make use of the Azure.Identity library to integrate with Entra ID and other token-based sources. Each client, including the AzureOpenAIClient, have constructor overloads that accept a TokenCredential instance.

For example:

AzureOpenAIClient azureClient = new(
    new Uri("https://your-azure-openai-resource.com"),
    new DefaultAzureCredential());

More discussion and links to further examples can be found in the Azure OpenAI README

github-actions[bot] commented 1 week ago

Hi @shouryashashank. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

github-actions[bot] commented 4 days ago

Hi @shouryashashank, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.