Skip to content

Commit c40fa17

Browse files
authored
Merge pull request #98409 from KingdomOfEnds/tsi-refresh
MSAL and ADAL note
2 parents 03e628d + 80a09b2 commit c40fa17

File tree

1 file changed

+49
-37
lines changed

1 file changed

+49
-37
lines changed

articles/time-series-insights/time-series-insights-authentication-and-authorization.md

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@ ms.reviewer: v-mamcge, jasonh, kfile
1010
ms.devlang: csharp
1111
ms.workload: big-data
1212
ms.topic: conceptual
13-
ms.date: 11/14/2019
13+
ms.date: 12/09/2019
1414
ms.custom: seodec18
1515
---
1616

1717
# Authentication and authorization for Azure Time Series Insights API
1818

1919
This document describes how to register an app in Azure Active Directory using the new Azure Active Directory blade. Apps registered in Azure Active Directory enable users to authenticate to and be authorized to use the Azure Time Series Insight API associated with a Time Series Insights environment.
2020

21+
> [!IMPORTANT]
22+
> Azure Time Series Insights supports both of the following authentication libraries:
23+
> * The more recent [Microsoft Authentication Library (MSAL)](https://docs.microsoft.com/azure/active-directory/develop/msal-overview)
24+
> * The [Azure Active Directory Authentication Library (ADAL)](https://docs.microsoft.com/azure/active-directory/develop/active-directory-authentication-libraries)
25+
2126
## Service principal
2227

2328
The following sections describe how to configure an application to access the Time Series Insights API on behalf of an app. The application may then query or publish reference data in the Time Series Insights environment using its own application credentials through Azure Active Directory.
@@ -71,30 +76,19 @@ Per **step 3**, separating your application's and your user credentials allows y
7176
7277
### Client app initialization
7378

74-
1. Use the **Application ID** and **Client Secret** (Application Key) from the Azure Active Directory app registration section to acquire the token on behalf of the application.
79+
* Developers may use the [Microsoft Authentication Library (MSAL)](https://docs.microsoft.com/azure/active-directory/develop/msal-overview) or [Azure Active Directory Authentication Library (ADAL)](https://docs.microsoft.com/azure/active-directory/develop/active-directory-authentication-libraries) to authenticate with Azure Time Series Insights.
7580

76-
In C#, the following code can acquire the token on behalf of the application. For a complete sample, see [Query data using C#](time-series-insights-query-data-csharp.md).
81+
* For example, to authenticate using ADAL:
7782

78-
```csharp
79-
// Enter your Active Directory tenant domain name
80-
var tenant = "YOUR_AD_TENANT.onmicrosoft.com";
81-
var authenticationContext = new AuthenticationContext(
82-
$"https://login.microsoftonline.com/{tenant}",
83-
TokenCache.DefaultShared);
83+
1. Use the **Application ID** and **Client Secret** (Application Key) from the Azure Active Directory app registration section to acquire the token on behalf of the application.
8484

85-
AuthenticationResult token = await authenticationContext.AcquireTokenAsync(
86-
// Set the resource URI to the Azure Time Series Insights API
87-
resource: "https://api.timeseries.azure.com/",
88-
clientCredential: new ClientCredential(
89-
// Application ID of application registered in Azure Active Directory
90-
clientId: "YOUR_APPLICATION_ID",
91-
// Application key of the application that's registered in Azure Active Directory
92-
clientSecret: "YOUR_CLIENT_APPLICATION_KEY"));
85+
1. In C#, the following code can acquire the token on behalf of the application. For a complete sample, see [Query data using C#](time-series-insights-query-data-csharp.md).
9386

94-
string accessToken = token.AccessToken;
95-
```
87+
[!code-csharp[csharpquery-example](~/samples-tsi/csharp-tsi-ga-sample/Program.cs?range=170-199)]
9688

97-
1. The token can then be passed in the `Authorization` header when the application calls the Time Series Insights API.
89+
1. The token can then be passed in the `Authorization` header when the application calls the Time Series Insights API.
90+
91+
* Alternatively, developers may choose to authenticate using MSAL. Read about [migrating to MSAL](https://docs.microsoft.com/azure/active-directory/develop/msal-net-migration) to learn more.
9892

9993
## Common headers and parameters
10094

@@ -106,39 +100,57 @@ To perform authenticated queries against the [Time Series Insights REST APIs](ht
106100

107101
> [!IMPORTANT]
108102
> The token must be issued exactly to the `https://api.timeseries.azure.com/` resource (also known as the "audience" of the token).
109-
> * Your [Postman](https://www.getpostman.com/) **AuthURL** with therefore conform to: `https://login.microsoftonline.com/microsoft.onmicrosoft.com/oauth2/authorize?resource=https://api.timeseries.azure.com/`
103+
> * Your [Postman](https://www.getpostman.com/) **AuthURL** will therefore be: `https://login.microsoftonline.com/microsoft.onmicrosoft.com/oauth2/authorize?resource=https://api.timeseries.azure.com/`
110104
111105
> [!TIP]
112106
> See the hosted Azure Time Series Insights [client SDK sample visualization](https://tsiclientsample.azurewebsites.net/) to see how to authenticate with the Time Series Insights APIs programmatically using the [JavaScript Client SDK](https://github.com/microsoft/tsiclient/blob/master/docs/API.md) along with charts and graphs.
113107
114108
### HTTP headers
115109

116-
Required request headers:
110+
Required request headers are described below.
117111

118-
- `Authorization` for authentication and authorization, a valid OAuth 2.0 Bearer token must be passed in the Authorization header. The token must be issued exactly to the `https://api.timeseries.azure.com/` resource (also known as the "audience" of the token).
112+
| Required request header | Description |
113+
| --- | --- |
114+
| Authorization | To authenticate with Time Series Insights, a valid OAuth 2.0 Bearer token must be passed in the **Authorization** header. |
119115

120-
Optional request headers:
116+
> [!IMPORTANT]
117+
> * The token must be issued exactly to `https://api.timeseries.azure.com/` (which is known as the "audience" of the token).
118+
> * Note that `https://api.timeseries.azure.com/` is valid but `https://api.timeseries.azure.com` is not.
121119
122-
- `Content-type` - only `application/json` is supported.
123-
- `x-ms-client-request-id` - a client request ID. Service records this value. Allows the service to trace operation across services.
124-
- `x-ms-client-session-id` - a client session ID. Service records this value. Allows the service to trace a group of related operations across services.
125-
- `x-ms-client-application-name` - name of the application that generated this request. Service records this value.
120+
Optional request headers are described below.
126121

127-
Response headers:
122+
| Optional request header | Description |
123+
| --- | --- |
124+
| Content-type | only `application/json` is supported. |
125+
| x-ms-client-request-id | A client request ID. The service records this value. Allows the service to trace operation across services. |
126+
| x-ms-client-session-id | A client session ID. The service records this value. Allows the service to trace a group of related operations across services. |
127+
| x-ms-client-application-name | Name of the application that generated this request. The service records this value. |
128128

129-
- `Content-type` - only `application/json` is supported.
130-
- `x-ms-request-id` - server-generated request ID. Can be used to contact Microsoft to investigate a request.
129+
Optional but recommended response headers are described below.
130+
131+
| Response header | Description |
132+
| --- | --- |
133+
| Content-type | Only `application/json` is supported. |
134+
| x-ms-request-id | Server-generated request ID. Can be used to contact Microsoft to investigate a request. |
131135

132136
### HTTP parameters
133137

134-
Required URL query string parameters:
138+
Required URL query string parameters depend on API version.
139+
140+
| Release | Possible API version values |
141+
| --- | --- |
142+
| General Availability | `api-version=2016-12-12`|
143+
| Preview | `api-version=2018-11-01-preview` |
144+
| Preview | `api-version=2018-08-15-preview` |
135145

136-
- `api-version=2016-12-12`
137-
- `api-version=2018-11-01-preview`
146+
> [!TIP]
147+
> The required API query value to use for each API is given in the [reference documentation](https://docs.microsoft.com/rest/api/time-series-insights/).
138148
139-
Optional URL query string parameters:
149+
Optional URL query string parameters include setting a timeout for HTTP request execution times.
140150

141-
- `timeout=<timeout>` – server-side timeout for the request execution. Applicable only to the [Get Environment Events](https://docs.microsoft.com/rest/api/time-series-insights/ga-query-api#get-environment-events-api) and [Get Environment Aggregates](https://docs.microsoft.com/rest/api/time-series-insights/ga-query-api#get-environment-aggregates-api) APIs. Timeout value should be in ISO 8601 duration format, for example `"PT20S"` and should be in the range `1-30 s`. Default value is `30 s`.
151+
| Optional query parameter | Description |
152+
| --- | --- |
153+
| `timeout=<timeout>` | Server-side timeout for HTTP request execution. Applicable only to the [Get Environment Events](https://docs.microsoft.com/rest/api/time-series-insights/ga-query-api#get-environment-events-api) and [Get Environment Aggregates](https://docs.microsoft.com/rest/api/time-series-insights/ga-query-api#get-environment-aggregates-api) APIs. Timeout value should be in ISO 8601 duration format, for example `"PT20S"` and should be in the range `1-30 s`. Default value is `30 s`. |
142154

143155
## Next steps
144156

@@ -148,4 +160,4 @@ Optional URL query string parameters:
148160

149161
- For API reference information, see [Query API reference](https://docs.microsoft.com/rest/api/time-series-insights/ga-query-api).
150162

151-
- Learn how to [create a service principal](../active-directory/develop/howto-create-service-principal-portal.md).
163+
- Learn how to [create a service principal](../active-directory/develop/howto-create-service-principal-portal.md).

0 commit comments

Comments
 (0)