avatar

目录
Azure笔记

Create access token

  1. Create a new App registration in Azure Active Directory.
  2. Create a new Client Secret in Certificates & secrets tab of the App registration created in step 1.
  3. Use the following code to generate the access token.
python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import adal

# Your Subscription ID
subscription_id = 'XXXXXXXXXXXXXXXXXX'
# Tenant ID for your Azure Subscription
TENANT_ID = 'XXXXXXXXXXXXXXXXXX'
# Your Service Principal CLIENT_ID
CLIENT_ID = 'XXXXXXXXXXXXXXXXXX'
# Your Service Principal CLIENT_SECRET created in step 2
CLIENT_SECRET = 'XXXXXXXXXXXXXXXXXX'

authority_url = 'https://login.microsoftonline.com/{}'.format(TENANT_ID)
context = adal.AuthenticationContext(authority_url)
token = context.acquire_token_with_client_credentials(
resource='https://management.azure.com/',
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET
)
print(token["accessToken"])
文章作者: Reborn
文章链接: https://reborn8888.github.io/2021/05/19/Azure%E7%AC%94%E8%AE%B0/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Reborn
打赏
  • 微信
    微信
  • 支付寶
    支付寶

评论