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/communication-services/tutorials/includes/hmac-header-python.md
+10-7Lines changed: 10 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,11 +41,11 @@ 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 `SignHmacTutorial.py`. Save this file to a known folder.
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.
45
45
46
46
## Add necessary imports
47
47
48
-
Update the `SignHmacTutorial.py` script with the following code to begin.
48
+
Update the `sign_hmac_tutorial.py` script with the following code to begin.
49
49
50
50
```python
51
51
import base64
@@ -60,7 +60,7 @@ from urllib import request
60
60
61
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).
62
62
63
-
Add the following code to the `SignHmacTutorial.py` script.
63
+
Add the following code to the `sign_hmac_tutorial.py` script.
64
64
65
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
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.
# Endpoint identities?api-version=2021-03-07 accepts list of scopes as a body.
78
-
scopes= ["chat"]
78
+
body={ "createTokenWithScopes": ["chat"] }
79
79
80
-
serialized_body = json.dumps(scopes)
80
+
serialized_body = json.dumps(body)
81
81
content = serialized_body.encode("utf-8")
82
82
```
83
83
84
84
## Create a content hash
85
85
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 `SignHmacTutorial.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 `sign_hmac_tutorial.py` script.
87
87
88
88
```python
89
89
defcompute_content_hash(content):
@@ -141,7 +141,7 @@ We'll now construct the string that we'll add to our authorization header.
141
141
1. Compute the signature.
142
142
1. Concatenate the string, which will be used in the authorization header.
143
143
144
-
Add the following code to the `SignHmacTutorial.py` script.
144
+
Add the following code to the `sign_hmac_tutorial.py` script.
145
145
146
146
```python
147
147
# Specify the 'x-ms-date' header as the current UTC timestamp according to the RFC1123 standard
0 commit comments