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
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.
21
21
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.
24
32
25
33
::: zone pivot="programming-language-csharp"
26
34
[!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
32
40
33
41
## Clean up resources
34
42
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).
41
44
42
-
You might also want to:
45
+
## Related content
43
46
47
+
-[Add voice calling to your app](../quickstarts/voice-video-calling/getting-started-with-calling.md)
44
48
-[Add chat to your app](../quickstarts/chat/get-started.md)
45
49
-[Create user access tokens](../quickstarts/identity/access-tokens.md)
46
50
-[Learn about client and server architecture](../concepts/identity-model.md#client-server-architecture)
- 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).
- 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.
20
20
21
21
## Sign an HTTP request with C#
22
22
@@ -34,13 +34,13 @@ The `hmac-sha256-signature` consists of:
34
34
- Host
35
35
- x-ms-content-sha256
36
36
37
-
## Setup
37
+
## Set up the authorization header
38
38
39
39
The following steps describe how to construct the authorization header.
40
40
41
41
### Create a new C# application
42
42
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`.
44
44
45
45
```console
46
46
dotnet new console -o SignHmacTutorial
@@ -87,7 +87,7 @@ namespace SignHmacTutorial
87
87
88
88
## Create a request message
89
89
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`).
91
91
92
92
Add the following code to the `Main` method.
93
93
@@ -143,20 +143,20 @@ Replace `resourceAccessKey` with an access key of your real Communication Servic
143
143
144
144
## Create an authorization header string
145
145
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.
147
147
148
148
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.
151
151
1. Compute a content hash.
152
152
1. Prepare a string to sign.
153
153
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
+
156
156
Add the following code to the `Main` method.
157
157
158
158
```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.
- 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).
18
18
- 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.
21
21
22
22
## Sign an HTTP request with Python
23
23
@@ -35,13 +35,13 @@ The `hmac-sha256-signature` consists of:
35
35
- Host
36
36
- x-ms-content-sha256
37
37
38
-
## Setup
38
+
## Set up the authorization header
39
39
40
40
The following steps describe how to construct the authorization header.
41
41
42
42
### Create a new Python script
43
43
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.
45
45
46
46
## Add necessary imports
47
47
@@ -58,12 +58,12 @@ from urllib import request
58
58
59
59
## Prepare data for the request
60
60
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).
62
62
63
63
Add the following code to the `sign_hmac_tutorial.py` script.
64
64
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.
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.
0 commit comments