惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
N
News and Events Feed by Topic
T
Tor Project blog
AI
AI
S
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Hacker News: Ask HN
Hacker News: Ask HN
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog
B
Blog
G
GRAHAM CLULEY
Recent Commits to openclaw:main
Recent Commits to openclaw:main
W
WeLiveSecurity
GbyAI
GbyAI
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
Check Point Blog
SecWiki News
SecWiki News
Y
Y Combinator Blog
I
Intezer
S
Securelist
WordPress大学
WordPress大学
小众软件
小众软件
Google DeepMind News
Google DeepMind News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
美团技术团队
Schneier on Security
Schneier on Security
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed
Jina AI
Jina AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Help Net Security
Help Net Security
P
Privacy International News Feed
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
The Register - Security
The Register - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Threatpost
H
Help Net Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
Google Developers Blog
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
Forbes - Security
Forbes - Security
C
Cisco Blogs
The GitHub Blog
The GitHub Blog
博客园 - 司徒正美

博客园 - 衡子

Ubuntu24.04更改SSH端口 记录安装过程 Azure CLI创建管理员用户 创建VMSS中的instance 创建不带公网IP的VM Azure LSv3系列VM 自动挂载NVMe本地磁盘 Azure AD访问Azure Storage Azure Linux VM使用Managed Identity获取Key-vault的Secret Azure AD SSO with Google Cloud Identity 通过VM SWAP OS DISK升级VM 通过API获取Azure KeyVault Securet Azure Front Door添加自定义域名 VM间网络PPS和带宽测试 VM间记录时延 Windows Terminal的一些配置 安装hping Azure解除不再使用Directory的关联 使用VSCode Remote Containers功能实现开发环境统一 Azure AKS容器网络详解
Azure获取access token的方法
衡子 · 2021-12-22 · via 博客园 - 衡子

Azure上有多种获取Access Token的方式,这里介绍通过rest api获取service principal的token,和通过azure cli获取用户token的方法。

一 获取token

1 通过rest api的方式获取service principal的access token

通过如下命令获取token

sub_id=xxxx-xxxx-xxxx-xxxx-xxxx
secret=xxxx-_xxxxm-xxxx-xxxx
client_id= xxxx-xxxx-xxxx-xxxx-xxxx
tenant_id= xxxx-xxxx-xxxx-xxxx-xxxx
token=$(curl -X POST -s -d "grant_type=client_credentials&client_id=$client_id&client_secret=$secret&resource=https%3A%2F%2Fmanagement.azure.com%2F" https://login.microsoftonline.com/$tenant_id/oauth2/token | jq -r .access_token)

2 通过azure命令行获取用户的access token

token=$(az account get-access-token | jq -r .accessToken)

二 验证token

通过Rest API获取Subscription信息

通过Service Principal的方式,只能获取已经授权的订阅:

curl -X GET -s -H "Authorization: Bearer $token" -H "Content-Type: application/json" https://management.azure.com/subscriptions?api-version=2020-01-01 | jq
{
  "value": [
  {
    "id": "/subscriptions/ xxxx-xxxx-xxxx-xxxx-xxxx",
    "authorizationSource": "RoleBased",
    "managedByTenants": [],
    "subscriptionId": " xxxx-xxxx-xxxx-xxxx-xxxx",
    "tenantId": " xxxx-xxxx-xxxx-xxxx-xxxx",
    "displayName": "xxxx",
    "state": "Enabled",
    "subscriptionPolicies": {
      "locationPlacementId": "Internal_2014-09-01",
      "quotaId": "Internal_2014-09-01",
      "spendingLimit": "Off"
    }
  }
  ],
  "count": {
  "type": "Total",
  "value": 1
  }
}

这里只有一个授权的订阅信息。

通过用户的Access-token:

curl -s -X GET -H "Authorization: Bearer $token" -H "Content-Type: application/json" https://management.azure.com/subscriptions?api-version=2020-01-01 | jq .value[].subscriptionId
"fXbXXXXX-cXXX-XXfX-a1dX-XfXXbbXXXX1X"
"XXcXXXXX-XccX-X1ca-XbXa-dfXdda1XeXaX"
"XXbXXXcc-aX1a-XX1X-Xbfd-1aXXbcXddfXd"
"bacXXXed-cXfc-XaXX-Xac1-XcXcXXda1dXe"
"XaXeX1fX-Xdae-XXXX-bXXX-XXbXaafcbbed"
"Xae1XXXe-fXXX-XXXX-aXXX-1X1XXbaXXXfX"
"XXdXXXXX-X1eX-XXdX-X1d1-XXXXbXXX111X"
"dX1aXeXf-XeXX-XbXX-XbaX-Xe1XXbcXfeXd"
"XXXXXX1d-cXXX-Xc1X-XfdX-cX1fXXfXXXcX"
"XfdXXdcc-aXXX-XbXf-XfXc-XdacXXXfddaX"
"XXXXXaXd-XXXX-XaXd-XfXf-cXacXXaXddfd"
"caXXbc1X-cfXX-XXeX-bbeX-XcXXbXXX1XdX"

这里有多个订阅的信息。