简体   繁体   English

如何使用服务主体或 oauth2 通过 azure Active Directory 获取用于 azure 存储帐户访问的令牌?

[英]How to fetch token for azure storage account access via azure active directory using service principal or oauth2?

I am looking for examples to fetch access token for azure storage account access via azure active directory with service principal in python我正在寻找示例来获取访问令牌以通过 azure 活动目录和 python 中的服务主体访问 azure 存储帐户

It seems like https://github.com/AzureAD/azure-activedirectory-library-for-python/blob/dev/sample/client_credentials_sample.py doesn't support service principal access似乎https://github.com/AzureAD/azure-activedirectory-library-for-python/blob/dev/sample/client_credentials_sample.py不支持服务主体访问

are there other ways in fetching token via service principal?还有其他方法可以通过服务主体获取令牌吗?

• Yes, you can surely fetch an access token for an Azure storage account via Azure Active Directory using a service principal, ie, an app registration by following the steps below as given in the below documentation link: - • 是的,您当然可以使用服务主体通过 Azure Active Directory 获取 Azure 存储帐户的访问令牌,即按照以下文档链接中给出的步骤进行应用注册:-

https://docs.microsoft.com/en-us/azure/developer/python/sdk/authentication-azure-hosted-apps?tabs=azure-portal%2Cazure-app-service https://docs.microsoft.com/en-us/azure/developer/python/sdk/authentication-azure-hosted-apps?tabs=azure-portal%2Cazure-app-service

As per the above documentation, you will have to host your python application code in a web app service and create a system assigned managed identity for it.根据上述文档,您必须将Python 应用程序代码托管在 Web 应用程序服务中,并为其创建系统分配的托管标识 Once created, then an application will be created in Azure AD with the same 'Object ID' as shown in the managed identity section of the web app service .创建后,将在 Azure AD 中创建具有相同“对象 ID”的应用程序,如 Web 应用服务的托管标识部分所示 Before moving onto this application created in Azure AD, assign the required roles to this system assigned managed identity through the 'IAM' tab .在转到在 Azure AD 中创建的此应用程序之前,请通过“IAM”选项卡将所需角色分配给此系统分配的托管标识 So, in your case, you should assign the role of 'Storage Account Contributor' to the 'System-assigned managed identity' created for the web app service.因此,在您的情况下,您应该将“存储帐户参与者”的角色分配给为 Web 应用服务创建的“系统分配的托管标识”

• Once, the role has been assigned, then go to the 'Enterprise application' and search for the 'Object ID' of the managed identity, you will encounter an application with the name of the web app service, in that, go to 'Permissions' under 'Security' tab and assign the required permissions and admin consent required to the application. • 一旦分配了角色,然后转到“企业应用程序”并搜索托管标识的“对象 ID” ,您将遇到一个具有 Web 应用服务名称的应用程序,其中,转到“ “安全”选项卡下的“权限”,并为应用程序分配所需的权限和管理员同意。 The permissions shown are those that are allowed under the scope of 'Storage Account Contributor' and similarly, you must assign permissions from it to the app/service principal .显示的权限是“存储帐户参与者”范围内允许的权限,同样,您必须将权限分配给应用程序/服务主体 Then ensure that you are correctly calling the environment variables of this application created in Azure AD regarding the managed identity and implement the 'DefaultAzureCredential' from the 'azure.identity' module .然后确保您正确调用在 Azure AD 中创建的有关托管标识的此应用程序的环境变量,并从“azure.identity”模块实现“DefaultAzureCredential” For this purpose, kindly refer to the below subsection of the above documentation: -为此,请参阅上述文档的以下小节:-

https://docs.microsoft.com/en-us/azure/developer/python/sdk/authentication-azure-hosted-apps?tabs=azure-portal%2Cazure-app-service#3---implement-defaultazurecredential-in-your-application https://docs.microsoft.com/en-us/azure/developer/python/sdk/authentication-azure-hosted-apps?tabs=azure-portal%2Cazure-app-service#3---implement-defaultazurecredential-在您的应用程序中

In this way, you can fetch an access token for the Azure storage account via Azure Active Directory using a service principal.通过这种方式,您可以使用服务主体通过 Azure Active Directory 获取 Azure 存储帐户的访问令牌。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过服务主体通过 Azure Key Vault 访问 Azure 存储帐户 - How to access Azure storage account Via Azure Key Vault by service principal 使用获得的 oauth2 令牌访问用户的 Azure Blob 存储 - Access Azure Blob storage of a user using oauth2 token obtained 使用服务主体访问 Azure blob 存储 - Using service principal to access Azure blob storage 使用 OAuth2 和 Azure 使用个人帐户 microsoft 登录 Active Directory - Login with OAuth2 And Azure Active Directory With Personal account microsoft 使用服务主体对 Azure Data Lake Storage Gen 2 进行 REST API 调用的 OAuth 令牌 - OAuth token for REST API call to Azure Data Lake Storage Gen 2 using service principal 使用Azure Active Directory作为Spring-boot REST服务的OAUTH2身份验证服务 - Using Azure Active Directory as an OAUTH2 Authentication service for a Spring-boot REST service 如何为只读 azure 访问创建 Azure 服务主体帐户 - How to craete Azure Service principal account for readonly azure access 如何从代码中设置 Azure Active Directory 服务主体的属性? - How to set properties of Azure Active Directory service principal from code? 使用 Azure Active Directory Oauth 的 Azure 服务管理 API 身份验证 - Azure Service Management API authentication using Azure Active Directory Oauth 如何使用 Azure Active Directory 在 Web 应用程序中刷新访问令牌 - How to refresh access token in web application using Azure Active Directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM