When calling the Azure Rest API, if it is an API belonging to Azure Resource Manager, you need to use Azure Active Directory (Azure AD) authentication to obtain a token (Token) before you can access it.
The following are the steps to create an Azure AD application and authorize it to access resources that manage Azure:
For a better reading experience, you can also click here.
Note
The following authentication methods are only applicable to Azure Resource Manager API. That is, the API with the endpoint management.chinacloudapi.cn
is not applicable to the API of Azure Service Manager (the API with the endpoint management.core.chinacloudapi.cn
).
Log in to your Azure account (PowerShell)
Set-AzureRmContext -SubscriptionId <subscription ID>Create AD applicationView the newly created application object and the attribute ApplicationId, which will be used to create service credentials, role settings and Access Token later.
$azureAdApplication = New-AzureRmADApplication -DisplayName "exampleapp" -HomePage "https://www.contoso.org" -IdentifierUris "https://www.contoso.org/example" -Password "<Your_Password>"
New-AzureRmADServicePrincipal -ApplicationId $azureAdApplication.ApplicationId
New-AzureRmRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $azureAdApplication.ApplicationIdThere are three permission settings for
RoleDefinitionName:
- Reader has read permissions for Azure resources.
- Contributor has administrative rights to Azure resources, but cannot authorize others.
- Owner has management rights to Azure resources and can also authorize others to manage them.
- telent-id corresponds to the telentID used in subscription information.
- application-id ApplicationID returned by creating the application.
- app password The password filled in when creating the application.
$tenlent_id = 'Your Sub Tenlent ID'; $client_id = 'Application ID'; $client_secret = 'Application Password'; $auth_url = 'https://login.chinacloudapi.cn/'.$tenlent_id.'/oauth2/token?api-version=1.0'; $auth = curl_init($auth_url); $post_data= 'grant_type=client_credentials&resource=https://management.chinacloudapi.cn/&client_id='.$client_id.'&client_secret='.urlencode($client_secret); curl_setopt_array($auth, array( CURLOPT_VERBOSE => 1, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $post_data, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HTTPHEADER => array( 'Content-Type: application/x-www-form-urlencoded' ) )); curl_exec($atuh); echo "\n";After executing the query, you will get the Token data, and access_token is the access Token.
{ "token_type": "Bearer", "expires_in": "3600", "expires_on": "1455680701", "not_before": "1455676801", "resource": "https://management.azure.com/", "access_token": "eyJ0eXAiOi…" }Then add the Authorization Header setting to the API request you want to access, and set its value to:
$token = 'eyJ0eXA…'; $host = 'management.chinacloudapi.cn'; $version = '2015-09-01'; $url = 'https://'.$host.'/subscriptions/5bbf0cbb-647d-4bd8-b4e6-26629f109bd7/resourceGroups/Default-MySql-ChinaNorth/providers/Microsoft.MySql/servers/poddbtest/databases/kevintest?api-version='.$version; $ch = curl_init($url); $data = array( 'properties' => array( 'charset' => 'utf8', 'collation' => 'utf8_general_ci' ), ); $json = json_encode($data); curl_setopt_array($ch, array( CURLOPT_VERBOSE => 1, CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => $json, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HTTPHEADER => array( 'Content-type:application/json', 'Authorization:Bearer '.$token ) )); $ret =curl_exec($ch); if (empty($ret)) { // some kind of an error happened echo 'Curl error: ' . curl_error($ch); } else { $info = curl_getinfo($ch); } echo "\n";
The above is the detailed content of Detailed example of how php obtains Azure Active Directory token. For more information, please follow other related articles on the PHP Chinese website!

错误801c03ed通常附带以下消息:管理员策略不允许此用户加入设备。此错误消息将阻止你安装Windows并加入网络,从而阻止你使用电脑,因此尽快解决此问题非常重要。什么是错误代码801c03ed?这是一个Windows安装错误,由于以下原因而发生:Azure设置不允许新用户加入。Azure上未启用设备对象。Azure面板中的硬件哈希出现故障。如何修复Windows801上的错误代码03c11ed?1.检查Intune设置登录到Azure门户。导航到“设备”,然后选择“设备设置”。将“用户可以将
![Active Directory 用户和计算机丢失 [以 3 种方式修复]](https://img.php.cn/upload/article/000/465/014/168196830849131.png)
ActiveDirectory用户和计算机(ADUC)丢失是许多WindowsPro用户报告的最令人沮丧的问题之一。ADUC是一个令人难以置信的MMC管理单元,它使管理员能够管理MicrosoftActiveDirectory。但是,由于某种原因,它在Windows服务器或Enterprise/Pro版本中缺失。让我们深入了解它丢失的原因以及我们如何修复它。Windows11是否有ActiveDirectory?ActiveDirectory是任何想要管理远程

旨在简化文档搜索,多种服务和平台的结合都是获得无与伦比性能的关键。在本文中,我们将探索一种将 Azure 认知服务的强大功能与 OpenAI 的功能相结合的整体方法。通过深入研究意图识别、文档过滤、特定领域的算法和文本摘要,您将学习创建一个不仅可以理解用户意图而且可以有效处理和呈现信息的系统。

本站12月17日消息,AzureOpenAI服务提供对OpenAI强大语言模型的RESTAPI访问,这些模型包括GPT-4、GPT-3.5-Turbo和嵌入模型系列。微软宣布进一步加强AzureOpenAI服务的功能,并为客户提供了最新的GPT-4TurbowithVision的公开预览版本这个先进的多模态AI模型继承了GPT-4Turbo的所有强大功能,并且还加入了图像处理和分析的能力。这样一来,我们就有了利用GPT-4处理更多任务的机会,比如改进无障碍辅助功能、解释和分析可视化数据,以及进行

本站8月16日消息,微软昨日发布了一条公告,宣布将从10月开始强制实施多因素身份验证(MFA)功能,以帮助降低账户被入侵的可能性。微软表示,MFA可以阻止99.2%以上的此类账户入侵攻击,因此该措施是强制性的。据介绍,这一过程将分为两个阶段逐步实施,本站总结如下:第1阶段:从10月开始,登录Azure门户、MicrosoftEntra管理中心和Intune管理中心都将需要MFA,但不会影响其他Azure客户端。第2阶段:从2025年初开始,MFA要求将逐步拓展到其他Azure客户端,例如Azur

微软详细介绍了它计划如何通过将多云支持引入其主要安全策略来进一步保护客户的安全。与此相一致,该公司旨在引入新功能和进步,以帮助从集中管理的角度加强安全性和控制。为了尝试向其客户引入更简单的安全解决方案,以便他们不会发现管理多云环境具有挑战性,微软决定将“MicrosoftDefenderforCloud的本机功能扩展到谷歌云平台(GCP)”。得益于GCP的支持,微软成为唯一一家为业界前三大平台提供原生多云保护的云提供商,这些平台分别是:微软Azure、亚马逊网络服务(AWS)

微软已发布 Windows Server Insider Preview 的新版本。本周的 build 25099 现在可以从Windows Server Insider 网站下载 ISO和 VHDX,但按照惯例,没有完整的变更日志可言,因此不清楚有什么新内容。微软再次表示该品牌尚未更新,在预览版中仍为 Windows Server 2022。此外,微软鼓励内部人员在Azure


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
