Skip to content

Commit 3502b83

Browse files
authored
Merge pull request #295249 from paulth1/comm-service-tutorials
[AQ] edit pass: Comm service tutorials
2 parents df848ce + 977ed0d commit 3502b83

File tree

6 files changed

+208
-200
lines changed

6 files changed

+208
-200
lines changed

articles/communication-services/tutorials/hmac-header-tutorial.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Learn how to sign an HTTP request with HMAC
2+
title: Tutorial - Learn How to Sign an HTTP Request with HMAC
33
titleSuffix: An Azure Communication Services tutorial
4-
description: Learn how to sign an HTTP request for Azure Communication Services using HMAC.
4+
description: Learn how to sign an HTTP request for Azure Communication Services by using HMAC.
55
author: alexandra142
66
manager: soricos
77
services: azure-communication-services
@@ -15,12 +15,20 @@ ms.custom: devx-track-python
1515
zone_pivot_groups: acs-programming-languages-csharp-python
1616
---
1717

18-
# Sign an HTTP request
18+
# Tutorial: Sign an HTTP request
1919

20-
In this tutorial, you'll learn how to sign an HTTP request with an HMAC signature.
20+
In this tutorial, you learn how to sign an HTTP request with a hash-based message authentication code (HMAC) signature.
2121

22-
>[!NOTE]
23-
>We strongly encourage to use [Azure SDKs](https://github.com/Azure/azure-sdk). Approach described here is a fallback option for cases when Azure SDKs can't be used for any reason.
22+
> [!NOTE]
23+
> We strongly encourage you to use [Azure SDKs](https://github.com/Azure/azure-sdk). The approach described here is a fallback option for cases when Azure SDKs can't be used for any reason.
24+
25+
In this tutorial, you learn how to:
26+
> [!div class="checklist"]
27+
> * Create a request message.
28+
> * Create a content hash.
29+
> * Compute a signature.
30+
> * Create an authorization header string.
31+
> * Add headers.
2432
2533
::: zone pivot="programming-language-csharp"
2634
[!INCLUDE [Sign an HTTP request with C#](./includes/hmac-header-csharp.md)]
@@ -32,15 +40,11 @@ In this tutorial, you'll learn how to sign an HTTP request with an HMAC signatur
3240

3341
## Clean up resources
3442

35-
To clean up and remove a Communication Services subscription, delete the resource or resource group. Deleting the resource group also deletes any other resources associated with it. You can find out more about [cleaning up Azure Communication Services resources](../quickstarts/create-communication-resource.md#clean-up-resources) and [cleaning Azure Functions resources](../../azure-functions/create-first-function-vs-code-csharp.md#clean-up-resources).
36-
37-
## Next steps
38-
39-
> [!div class="nextstepaction"]
40-
> [Add voice calling to your app](../quickstarts/voice-video-calling/getting-started-with-calling.md)
43+
To clean up and remove a Communication Services subscription, delete the resource or resource group. Deleting the resource group also deletes any other resources associated with it. You can find out more about how to [clean up Azure Communication Services resources](../quickstarts/create-communication-resource.md#clean-up-resources) and [clean up Azure Functions resources](../../azure-functions/create-first-function-vs-code-csharp.md#clean-up-resources).
4144

42-
You might also want to:
45+
## Related content
4346

47+
- [Add voice calling to your app](../quickstarts/voice-video-calling/getting-started-with-calling.md)
4448
- [Add chat to your app](../quickstarts/chat/get-started.md)
4549
- [Create user access tokens](../quickstarts/identity/access-tokens.md)
4650
- [Learn about client and server architecture](../concepts/identity-model.md#client-server-architecture)

articles/communication-services/tutorials/includes/hmac-header-csharp.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Sign an HTTP request with C#
2+
title: Sign an HTTP Request with C#
33
description: This tutorial explains the C# version of signing an HTTP request with an HMAC signature for Azure Communication Services.
44
author: alexandra142
55
manager: soricos
@@ -14,9 +14,9 @@ ms.service: azure-communication-services
1414

1515
Before you get started, make sure to:
1616

17-
- Create an Azure account with an active subscription. For details, see [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
17+
- Create an Azure account with an active subscription. If you don't have an Azure subscription, see [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
1818
- Install [Visual Studio](https://visualstudio.microsoft.com/downloads/).
19-
- Create an Azure Communication Services resource. For details, see [Create an Azure Communication Services resource](../../quickstarts/create-communication-resource.md). You'll need to record your **resourceEndpoint** and **resourceAccessKey** for this tutorial.
19+
- Create an Azure Communication Services resource. If you don't have a resource, see [Create a Communication Services resource](../../quickstarts/create-communication-resource.md). You need to record your `resourceEndpoint` and `resourceAccessKey` parameters for this tutorial.
2020

2121
## Sign an HTTP request with C#
2222

@@ -34,13 +34,13 @@ The `hmac-sha256-signature` consists of:
3434
- Host
3535
- x-ms-content-sha256
3636

37-
## Setup
37+
## Set up the authorization header
3838

3939
The following steps describe how to construct the authorization header.
4040

4141
### Create a new C# application
4242

43-
In a console window, such as cmd, PowerShell, or Bash, use the `dotnet new` command to create a new console app with the name `SignHmacTutorial`. This command creates a simple "Hello World" C# project with a single source file: **Program.cs**.
43+
In a console window, such as cmd, PowerShell, or Bash, use the `dotnet new` command to create a new console app with the name `SignHmacTutorial`. This command creates a simple "Hello World" C# project with a single source file: `Program.cs`.
4444

4545
```console
4646
dotnet new console -o SignHmacTutorial
@@ -87,7 +87,7 @@ namespace SignHmacTutorial
8787

8888
## Create a request message
8989

90-
For this example, we'll sign a request to create a new identity by using the Communication Services Authentication API (version `2021-03-07`).
90+
For this example, you sign a request to create a new identity by using the Communication Services Authentication API (version `2021-03-07`).
9191

9292
Add the following code to the `Main` method.
9393

@@ -143,20 +143,20 @@ Replace `resourceAccessKey` with an access key of your real Communication Servic
143143

144144
## Create an authorization header string
145145

146-
We'll now construct the string that we'll add to our authorization header.
146+
Now you construct the string that you add to your authorization header.
147147

148148
1. Prepare values for the headers to be signed.
149-
1. Specify the current timestamp using the Coordinated Universal Time (UTC) timezone.
150-
1. Get the request authority (DNS host name or IP address and the port number).
149+
1. Specify the current timestamp by using the Coordinated Universal Time (UTC) timezone.
150+
1. Get the request authority. Use the Domain Name System (DNS) host name or IP address and the port number.
151151
1. Compute a content hash.
152152
1. Prepare a string to sign.
153153
1. Compute the signature.
154-
1. Concatenate the string, which will be used in the authorization header.
155-
154+
1. Concatenate the string, which is used in the authorization header.
155+
156156
Add the following code to the `Main` method.
157157

158158
```csharp
159-
// Specify the 'x-ms-date' header as the current UTC timestamp according to the RFC1123 standard
159+
// Specify the 'x-ms-date' header as the current UTC timestamp according to the RFC1123 standard.
160160
var date = DateTimeOffset.UtcNow.ToString("r", CultureInfo.InvariantCulture);
161161
// Get the host name corresponding with the 'host' header.
162162
var host = requestUri.Authority;
@@ -173,7 +173,7 @@ var authorizationHeader = $"HMAC-SHA256 SignedHeaders=x-ms-date;host;x-ms-conten
173173

174174
## Add headers to requestMessage
175175

176-
Use the following code to add the required headers to your `requestMessage`.
176+
Use the following code to add the required headers to your `requestMessage` parameter.
177177

178178
```csharp
179179
// Add a date header.

articles/communication-services/tutorials/includes/hmac-header-python.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Sign an HTTP request with Python
2+
title: Sign an HTTP Request with Python
33
description: This tutorial explains the Python version of signing an HTTP request with an HMAC signature for Azure Communication Services.
44
author: maximrytych-ms
55
manager: anitharaju
@@ -14,10 +14,10 @@ ms.service: azure-communication-services
1414

1515
Before you get started, make sure to:
1616

17-
- Create an Azure account with an active subscription. For details, see [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
17+
- Create an Azure account with an active subscription. If you don't have an Azure subscription, see [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
1818
- Download and install [Python](https://www.python.org/).
19-
- Download and install [Visual Studio Code](https://code.visualstudio.com/) or other IDE that supports Python.
20-
- Create an Azure Communication Services resource. For details, see [Create an Azure Communication Services resource](../../quickstarts/create-communication-resource.md). You'll need your **resource_endpoint_name** and **resource_endpoint_secret** for this tutorial.
19+
- Download and install [Visual Studio Code](https://code.visualstudio.com/) or another integrated development environment (IDE) that supports Python.
20+
- Create an Azure Communication Services resource. If you don't have a resource, see [Create a Communication Services resource](../../quickstarts/create-communication-resource.md). You need your `resource_endpoint_name` and `resource_endpoint_secret` parameters for this tutorial.
2121

2222
## Sign an HTTP request with Python
2323

@@ -35,13 +35,13 @@ The `hmac-sha256-signature` consists of:
3535
- Host
3636
- x-ms-content-sha256
3737

38-
## Setup
38+
## Set up the authorization header
3939

4040
The following steps describe how to construct the authorization header.
4141

4242
### Create a new Python script
4343

44-
Open Visual Studio Code or other IDE or editor of your choice and create a new file named `sign_hmac_tutorial.py`. Save this file to a known folder.
44+
Open Visual Studio Code or another IDE or editor of your choice. Create a new file named `sign_hmac_tutorial.py`. Save this file to a known folder.
4545

4646
## Add necessary imports
4747

@@ -58,12 +58,12 @@ from urllib import request
5858

5959
## Prepare data for the request
6060

61-
For this example, we'll sign a request to create a new identity by using the Communication Services Authentication API [(version `2021-03-07`)](https://github.com/Azure/azure-rest-api-specs/tree/main/specification/communication/data-plane/Identity/stable/2021-03-07).
61+
For this example, you sign a request to create a new identity by using the Communication Services Authentication API [(version `2021-03-07`)](https://github.com/Azure/azure-rest-api-specs/tree/main/specification/communication/data-plane/Identity/stable/2021-03-07).
6262

6363
Add the following code to the `sign_hmac_tutorial.py` script.
6464

65-
- Replace `resource_endpoint_name` with your real resource endpoint name value. This value can be found in Overview section of your Azure Communication Services resource. It's the value of "Endpoint" after "https://".
66-
- Replace `resource_endpoint_secret` with your real resource endpoint secret value. This value can be found in Keys section of your Azure Communication Services resource. It's the value of "Key" - either primary or secondary.
65+
- Replace `resource_endpoint_name` with your real resource endpoint name value. You can find this value in the **Overview** section of your Communication Services resource. It's the value of `Endpoint` after `https://`.
66+
- Replace `resource_endpoint_secret` with your real resource endpoint secret value. You can find this value in the **Keys** section of your Communication Services resource. It's the value of **Key**, which is either primary or secondary.
6767

6868
```python
6969
host = "resource_endpoint_name"
@@ -74,7 +74,7 @@ secret = "resource_endpoint_secret"
7474
# Create a uri you are going to call.
7575
request_uri = f"{resource_endpoint}{path_and_query}"
7676

77-
# Endpoint identities?api-version=2021-03-07 accepts list of scopes as a body.
77+
# Endpoint identities?api-version=2021-03-07 accepts the list of scopes as a body.
7878
body = { "createTokenWithScopes": ["chat"] }
7979

8080
serialized_body = json.dumps(body)
@@ -83,7 +83,7 @@ content = serialized_body.encode("utf-8")
8383

8484
## Create a content hash
8585

86-
The content hash is a part of your HMAC signature. Use the following code to compute the content hash. You can add this method to `sign_hmac_tutorial.py` script.
86+
The content hash is a part of your HMAC signature. Use the following code to compute the content hash. You can add this method to the `sign_hmac_tutorial.py` script.
8787

8888
```python
8989
def compute_content_hash(content):
@@ -109,9 +109,9 @@ def compute_signature(string_to_sign, secret):
109109
return signature
110110
```
111111

112-
## Get current UTC timestamp according to the RFC1123 standard
112+
## Get a current UTC timestamp according to the RFC1123 standard
113113

114-
Use the following code to get desired date format independent of locale settings.
114+
Use the following code to get the date format that you want that's independent of locale settings.
115115

116116
```python
117117
def format_date(dt):
@@ -131,20 +131,20 @@ def format_date(dt):
131131

132132
## Create an authorization header string
133133

134-
We'll now construct the string that we'll add to our authorization header.
134+
Now you construct the string that you add to your authorization header.
135135

136136
1. Prepare values for the headers to be signed.
137-
1. Specify the current timestamp using the Coordinated Universal Time (UTC) timezone.
138-
1. Get the request authority (DNS host name or IP address and the port number).
137+
1. Specify the current timestamp by using the Coordinated Universal Time (UTC) timezone.
138+
1. Get the request authority. Use the Domain Name System (DNS) host name or IP address and the port number.
139139
1. Compute a content hash.
140140
1. Prepare a string to sign.
141141
1. Compute the signature.
142-
1. Concatenate the string, which will be used in the authorization header.
143-
142+
1. Concatenate the string, which is used in the authorization header.
143+
144144
Add the following code to the `sign_hmac_tutorial.py` script.
145145

146146
```python
147-
# Specify the 'x-ms-date' header as the current UTC timestamp according to the RFC1123 standard
147+
# Specify the 'x-ms-date' header as the current UTC timestamp according to the RFC1123 standard.
148148
utc_now = datetime.now(timezone.utc)
149149
date = format_date(utc_now)
150150
# Compute a content hash for the 'x-ms-content-sha256' header.
@@ -168,13 +168,13 @@ request_headers = {}
168168
# Add a date header.
169169
request_headers["x-ms-date"] = date
170170

171-
# Add content hash header.
171+
# Add a content hash header.
172172
request_headers["x-ms-content-sha256"] = content_hash
173173

174-
# Add authorization header.
174+
# Add an authorization header.
175175
request_headers["Authorization"] = authorization_header
176176

177-
# Add content type header.
177+
# Add a content type header.
178178
request_headers["Content-Type"] = "application/json"
179179
```
180180

0 commit comments

Comments
 (0)