分享好友 最新动态首页 最新动态分类 切换频道
Authenticate your Azure OpenAI Based App - Key or Key-less
2024-12-26 13:52

If you’re using Azure OpenAI, then you must be aware that the most common and easiest way to authenticate our application is using app-key.

The key-based authentication approach is very popular because it is very straightforward. Let's have a quick look at the below code snippet:



The above code snippet constructs the AzureOpenAI client object using api-key,api-version, and endpoint. Then, this object makes a call to the completion endpoint with the required parameters.

Of course, key-based authentication works very well for experimentation purposes, like in the above case, but it is not very well suited for enterprise-grade applications that will soon be in production.

So, why should we never use keys to authenticate Azure OpenAI in production?

In a production capacity, it is generally not recommended to use keys for Azure OpenAI authentication, and there are several key reasons behind for this. Here are the reasons.

  • Key Exposure: Keys may inadvertently be committed to source control by developers or stored in some insecure locations, and if the key is exposed, unauthorized individuals can easily gain access to the Azure environment.
  • Granular Permissions: Keys are good for local development and testing but not for production environments as they don’t follow the principle of least privilege. They give too much access to anyone who uses them, which can lead to misuse.
  • Shareable: It is very easy to share keys with both good and bad intentions, intentionally or unintentionally which leads to potential security breaks.
  • Rotation being hard: As keys can’t rotate automatically, we need manual intervention to do the rotation which might be too time-consuming and cumbersome, specifically in a production deployment. Just one instance of compromise and all the instances where that are used to generate tokens will need an update.

One should avoid using keys to authenticate and use Managed Identities for Azure resources. There are multiple benefits of Managed Identities.

  • Superior security: Managed identities offer a significant improvement to security by providing tokens which are generated by Azure. This eventually means, that we no longer need to handle credentials directly.
  • Granular Access Control: With Managed Identities, assigning specific roles and permissions is straightforward. This ensures that each identity has only the access it needs, adhering to the principle of least privilege. It emphasizes on granting the bare minimum required permissions.
  • No rotation required: As the managed identity feature takes care of credential management for us, we do not need to store or manually rotate credentials, which minimizes the risk of credential exposure.

Let’s get started by updating our source code first. Here are the code changes.



Now, if you simply execute this code, it won’t work. Here is the error, you can expect.

The error clearly says, there is something wrong with the authentication part and this happened because of these two reasons.

  • no default credentials are set
  • no permissions are granted to the user, who is executing the application

Here, we have multiple ways to sort out our default credential issue. Here is the complete documentation of the DefaultAzureCredential class, which sits in Azure. Identity namespace.

You can choose any of these ways to resolve this. I used CLI and executed the commands below in the PowerShell terminal.



If you’re not able to execute the above commands then make sure you’ve required PowerShell modules installed:



Once you get connected, you will see that your available subscriptions are listed in your terminal.

The next step is to make sure that whoever is running the code has permission to access the OpenAI service. This can be done either with Azure CLI or using the Azure portal.

Using Azure CLI (make sure to set required environment variables).


最新文章
21独家|还原极越8月董事会内幕:“极越的崩盘,早在这次董事会便注定”
极越近期的爆雷,在8月的公司董事会上便已经有了苗头。21汽车从多位高层信源处获悉,今年8月中旬,极越召开了一次90分钟董事会,在这个会上,极越管理层除了向董事会汇报上半年的花钱情况、新款车是否继续研发,同时董事会还讨论了一个重大
2024 年支付宝广告投放|支付宝广告代理商|支付宝灯火广告
支付宝作为中国领先的移动支付和生活服务平台,具备巨大的用户群体和丰富的数据资源,使其成为一种潜力巨大的广告投放推广平台。本文将对支付宝内广告投放推广进行多方面的详细分析。首先,支付宝广告投放推广的优势在于其庞大的用户基础。
AAB 扶正!APK 将退出历史舞台
令我惊讶的是,这样一条“旧闻”最近却被炒得沸沸扬扬,原来竟还是因为蹭了鸿蒙的热度:要知道 AAB 的首次亮相是在2018年的 GoogleI/O 上,难道彼时谷歌就遇见到鸿蒙的出现了? 不过客观来说,AAB 虽
ai怎么制作2.5D风格的三角形建筑图标?
今天我们就来看看ai绘制2.5d效果的图标,该怎么绘制呢?下面我们就来看看详细的绘制方法。怎么样,看上去简简单单一个图形,但要是用形状一块块去拼凑的话,费时并且很难做得规范,像素妹在这里教大家简单规范地三步完成!一、做参考线1.打
b2b2c网上商城系统源代码怎么做?
  企业对于商城系统的需求不断增加,如今只有开发一个b2b2c网上商城系统源码才能够充分满足企业的需求。b2b2c商城系统源代码的开发需要注意几个方面,那么进行b2b2c网上商城系统源代码开发具体要怎么做呢?  在进行商城系统源代码开发之
android游戏app源码 成品漫画源码网站下载 全攻略
微信开发可以分为公众号开发和小程序开发两个方面。公众号开发主要涉及与用户的互动,包括消息推送、菜单设置、用户管理等。开发者需要通过微信公众平台申请一个公众号,并获取相应的开发者权限。公众号开发可以通过自定义菜单、图文消息、
2025年邢台应用技术职业学院院校代码是多少?附招生专业代码
2025年邢台应用技术职业学院院校代码为14742,此为教育部统一编码。其在各省的招生代码各有不同,如在天津招生的代码是184100,在黑龙江招生的代码是4148等。2025年邢台应用技术职业学院暂未公布具体的招生计划,因此这里暂以2024年信息为
Discover(高沃)+数据分析师+电话一面
nbsp;nbsp;8月2日投简历nbsp;8月3日电话约面nbsp;8月8日面试大概50分钟。nbsp; nbsp;nbsp;面试英文,但后续介绍项目的时候也用到了中文。nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;自我介绍nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;
excel表格怎么打乱顺序排列
打乱Excel表格顺序排列可以通过使用随机数排序、使用VBA代码或利用Excel的排序和筛选功能。生成随机数与排序功能结合使用是一种简单直接的方法。首先,在表格旁边的空列生成一组随机数,然后依据这些随机数进行排序,便能打乱原来的数据顺
2022能编辑pdf的免费软件 能编辑pdf软件最新下载地址
今天小编给大家产生2022能编辑pdf的专业软件最新版下载地址的共享。想来很多客户不知道一键生成PDF的app有哪几种吧,尤其是能够实现手机端在线制作,并进行了多种多样格式间的转换,方便大家的阅读体验,下面小编就为大家整理了这几款PDF类
相关文章
推荐文章
发表评论
0评