You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-monitor/essentials/rest-api-walkthrough.md
+2-35Lines changed: 2 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,42 +20,9 @@ Retrieve metric definitions, dimension values, and metric values using the Azure
20
20
Request submitted using the Azure Monitor API use the Azure Resource Manager authentication model. All requests are authenticated with Microsoft Entra ID. One approach to authenticating the client application is to create a Microsoft Entra service principal and retrieve an authentication token. You can create a Microsoft Entra service principal using the Azure portal, CLI, or PowerShell. For more information, see [Register an App to request authorization tokens and work with APIs](../logs/api/register-app-for-token.md).
21
21
22
22
### Retrieve a token
23
-
Once you've created a service principal, retrieve an access token using a REST call. Submit the following request using the `appId` and `password` for your service principal or app:
23
+
Once you've created a service principal, retrieve an access token. specify resource=https://management.azure.com in the request to get a token.
24
24
25
-
```HTTP
26
-
27
-
POST /<tenant-id>/oauth2/token
28
-
Host: https://login.microsoftonline.com
29
-
Content-Type: application/x-www-form-urlencoded
30
-
31
-
grant_type=client_credentials
32
-
&client_id=<app-client-id>
33
-
&resource=https://management.azure.com
34
-
&client_secret=<password>
35
-
36
-
```
37
-
38
-
For example
39
-
40
-
```bash
41
-
curl --location --request POST 'https://login.microsoftonline.com/abcd1234-5849-4a5d-a2eb-5267eae1bbc7/oauth2/token' \
Copy file name to clipboardExpand all lines: articles/azure-monitor/includes/get-a-token.md
+24-25Lines changed: 24 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,3 @@
1
-
2
1
---
3
2
ms.service: azure-monitor
4
3
ms.topic: include
@@ -7,7 +6,7 @@ ms.author: edbaynash
7
6
author: EdB-MSFT
8
7
---
9
8
10
-
You can get a token for your rest calls using any of the following
9
+
Get a token using any of the following
11
10
- CLI
12
11
- REST API
13
12
- SDK
@@ -20,25 +19,13 @@ Resources include:
20
19
-https://monitoring.azure.com
21
20
22
21
23
-
## [CLI](#tab/cli)
24
-
25
-
To get a token using CLI, you can use the following command
26
-
27
-
```bash
28
-
az account get-access-token
29
-
```
30
-
31
-
For morte information see [az account get-access-token](/cli/azure/account?view=azure-cli-latest#az-account-get-access-token)
32
22
33
23
34
24
## [REST](#tab/rest)
35
25
36
26
Use the following REST API call to get a token.
37
-
this request uses a client ID and client secret to authenticate the request. The client ID and client secret are obtained when you register your application with Azure AD. For more information see [Register an App to request authorization tokens and work with APIs](/azure/azure-monitor/logs/api/register-app-for-token?tabs=portal)
38
-
39
-
27
+
This request uses a client ID and client secret to authenticate the request. The client ID and client secret are obtained when you register your application with Microsoft Entra ID. For more information, see [Register an App to request authorization tokens and work with APIs](/azure/azure-monitor/logs/api/register-app-for-token?tabs=portal)
40
28
41
-
-
42
29
43
30
```console
44
31
curl -X POST 'https://login.microsoftonline.com/<tennant ID>/oauth2/token' \
@@ -63,20 +50,30 @@ The response body appears in the following format:
63
50
}
64
51
```
65
52
53
+
## [CLI](#tab/cli)
54
+
55
+
To get a token using CLI, you can use the following command
56
+
57
+
```bash
58
+
az account get-access-token
59
+
```
60
+
61
+
For more information, see [az account get-access-token](/cli/azure/account?view=azure-cli-latest#az-account-get-access-token)
62
+
66
63
## [SDK](#tab/SDK)
67
64
68
65
You can use the SDK to get a token. The following code is an example of how to get a token using the SDK.
69
66
70
67
### .NET
71
68
72
-
The following code shows how to get a token using the Azure.Identity library It requires a client ID and client secret to authenticate the request.
69
+
The following code shows how to get a token using the Azure.Identity library It requires a client ID and client secret to authenticate the request.
Alternatively you can use the DefaultAzureCredential class to get a token. This uses the default Azure credentials to authenticate the request and does not require a client ID or client secret.
76
+
Alternatively you can use the DefaultAzureCredential class to get a token. This uses the default Azure credentials to authenticate the request and doesn't require a client ID or client secret.
80
77
81
78
```csharp
82
79
varcredential=newDefaultAzureCredential();
@@ -97,23 +94,23 @@ var credential = new DefaultAzureCredential(
For more information see [DefaultAzureCredential Class](/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet)
97
+
For more information, see [DefaultAzureCredential Class](/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet)
101
98
102
99
103
100
### Node.js
104
101
105
-
For information on authentication use Javascript and NodeJS, see [How to authenticate JavaScript apps to Azure services using the Azure SDK for JavaScript](/azure/developer/javascript/sdk/authentication/overview)
102
+
For information on authentication use JavaScript and NodeJS, see [How to authenticate JavaScript apps to Azure services using the Azure SDK for JavaScript](/azure/developer/javascript/sdk/authentication/overview)
106
103
107
104
108
-
The following code shows how to get a token using the DefaultAzureCredential class. This uses the default Azure credentials to authenticate the request and does not require a client ID or client secret.
105
+
The following code shows how to get a token using the DefaultAzureCredential class. This uses the default Azure credentials to authenticate the request and doesn't require a client ID or client secret.
For more information see [ClientSecretCredential Class](/javascript/api/@azure/identity/clientsecretcredential?view=azure-node-latest)
126
+
For more information, see [ClientSecretCredential Class](/javascript/api/@azure/identity/clientsecretcredential?view=azure-node-latest)
130
127
131
128
### Python
132
129
133
-
The following code shows how to get a token using the DefaultAzureCredential class. This uses the default Azure credentials to authenticate the request and does not require a client ID or client secret.
130
+
The following code shows how to get a token using the DefaultAzureCredential class. This uses the default Azure credentials to authenticate the request and doesn't require a client ID or client secret.
0 commit comments