Skip to content

Commit e36eadb

Browse files
committed
fiixes
1 parent 6e14d59 commit e36eadb

File tree

2 files changed

+26
-60
lines changed

2 files changed

+26
-60
lines changed

articles/azure-monitor/essentials/rest-api-walkthrough.md

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,9 @@ Retrieve metric definitions, dimension values, and metric values using the Azure
2020
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).
2121

2222
### 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.
2424

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' \
42-
--header 'Content-Type: application/x-www-form-urlencoded' \
43-
--data-urlencode 'grant_type=client_credentials' \
44-
--data-urlencode 'client_id=0123b56a-c987-1234-abcd-1a2b3c4d5e6f' \
45-
--data-urlencode 'client_secret=123456.ABCDE.~XYZ876123ABceDb0000' \
46-
--data-urlencode 'resource=https://management.azure.com'
47-
48-
```
49-
A successful request receives an access token in the response:
50-
51-
```HTTP
52-
{
53-
token_type": "Bearer",
54-
"expires_in": "86399",
55-
"ext_expires_in": "86399",
56-
"access_token": "eyJ0eXAiOiJKV1QiLCJ.....Ax"
57-
}
58-
```
25+
[!INCLUDE [Get a token](../includes/get-a-token.md)]
5926

6027

6128

articles/azure-monitor/includes/get-a-token.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
---
32
ms.service: azure-monitor
43
ms.topic: include
@@ -7,7 +6,7 @@ ms.author: edbaynash
76
author: EdB-MSFT
87
---
98

10-
You can get a token for your rest calls using any of the following
9+
Get a token using any of the following
1110
- CLI
1211
- REST API
1312
- SDK
@@ -20,25 +19,13 @@ Resources include:
2019
- https://monitoring.azure.com
2120

2221

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)
3222

3323

3424
## [REST](#tab/rest)
3525

3626
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)
4028

41-
-
4229

4330
```console
4431
curl -X POST 'https://login.microsoftonline.com/<tennant ID>/oauth2/token' \
@@ -63,20 +50,30 @@ The response body appears in the following format:
6350
}
6451
```
6552

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+
6663
## [SDK](#tab/SDK)
6764

6865
You can use the SDK to get a token. The following code is an example of how to get a token using the SDK.
6966

7067
### .NET
7168

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.
7370
```csharp
7471
var context = new AuthenticationContext("https://login.microsoftonline.com/<tennant ID>");
7572
var clientCredential = new ClientCredential("<your apps client ID>", "<your apps client secret>");
7673
var result = context.AcquireTokenAsync("https://monitoring.azure.com", clientCredential).Result;
7774
```
7875

79-
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.
8077

8178
```csharp
8279
var credential = new DefaultAzureCredential();
@@ -97,23 +94,23 @@ var credential = new DefaultAzureCredential(
9794
var token = credential.GetToken(new TokenRequestContext(new[] { "https://management.azure.com/.default" }));
9895

9996
```
100-
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)
10198

10299

103100
### Node.js
104101

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)
106103

107104

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.
109106

110107
```javascript
111108
const { DefaultAzureCredential } = require("@azure/identity");
112109

113110
const credential = new DefaultAzureCredential();
114111
const accessToken = await credential.getToken("https://management.azure.com/.default");
115112
```
116-
For more information see [DefaultAzureCredential Class](/javascript/api/@azure/identity/defaultazurecredential?view=azure-node-latest)
113+
For more information, see [DefaultAzureCredential Class](/javascript/api/@azure/identity/defaultazurecredential?view=azure-node-latest)
117114

118115
Alternatively you can use the ClientSecretCredential class to get a token. This requires a client ID and client secret to authenticate the request.
119116

@@ -126,11 +123,11 @@ credential = ClientSecretCredential(
126123
)
127124
const accessToken = await credential.getToken("https://management.azure.com/.default");
128125
```
129-
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)
130127

131128
### Python
132129

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.
134131

135132
```python
136133
from azure.identity import DefaultAzureCredential
@@ -139,7 +136,7 @@ credential = DefaultAzureCredential()
139136
token = credential.get_token('https://management.azure.com/.default')
140137
print(token.token)
141138
```
142-
For more information see [DefaultAzureCredential Class](/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python)
139+
For more information, see [DefaultAzureCredential Class](/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python)
143140

144141
Alternatively you can use the ClientSecretCredential class to get a token. This requires a client ID and client secret to authenticate the request.
145142

@@ -155,4 +152,6 @@ token = credential2.get_token("https://management.azure.com/.default")
155152
print(token.token)
156153
```
157154

158-
for more information see [ClientSecretCredential Class](/python/api/azure-identity/azure.identity.clientsecretcredential?view=azure-python)
155+
For more information see [ClientSecretCredential Class](/python/api/azure-identity/azure.identity.clientsecretcredential?view=azure-python)
156+
157+
---

0 commit comments

Comments
 (0)