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/azure-signalr/signalr-tutorial-authenticate-azure-functions.md
+25-25Lines changed: 25 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ Your application will access a SignalR Service instance. Use the following step
50
50
|**Pricing Tier**| Free |
51
51
|**Service mode**| Serverless |
52
52
53
-
1. Select **Review + Create".
53
+
1. Select **Review + Create**.
54
54
1. Select **Create**.
55
55
56
56
@@ -89,26 +89,26 @@ By default, the generated project includes a *host.json* file containing the ext
89
89
90
90
### Configure application settings
91
91
92
-
When running and debugging the Azure Functions runtime locally, application settings are read by the function app from **local.settings.json**. Update this file with the connection strings of the SignalR Service instance and the storage account that you created earlier.
92
+
When running and debugging the Azure Functions runtime locally, application settings are read by the function app from *local.settings.json*. Update this file with the connection strings of the SignalR Service instance and the storage account that you created earlier.
93
93
94
94
1. Replace the content of *local.settings.json* with the following code:
* Enter the Azure SignalR Service connection string into the' AzureSignalRConnectionString' setting.
107
+
* Enter the Azure SignalR Service connection string into the `AzureSignalRConnectionString` setting.
108
108
109
109
Navigate to your SignalR Service in the Azure portal. In the **Settings** section, locate the **Keys** setting. Select the **Copy** button to the right of the connection string to copy it to your clipboard. You can use either the primary or secondary connection string.
110
110
111
-
* Enter the storage account connection string into the' AzureWebJobsStorage' setting.
111
+
* Enter the storage account connection string into the `AzureWebJobsStorage` setting.
112
112
113
113
Navigate to your storage account in the Azure portal. In the **Security + networking** section, locate the **Access keys** setting. Select the **Copy** button to the right of the connection string to copy it to your clipboard. You can use either the primary or secondary connection string.
114
114
@@ -117,12 +117,12 @@ When running and debugging the Azure Functions runtime locally, application sett
117
117
118
118
### Create a function to authenticate users to SignalR Service
119
119
120
-
When the chat app first opens in the browser, it requires valid connection credentials to connect to Azure SignalR Service. You'll create an HTTP triggered function named *negotiate* in your function app to return this connection information.
120
+
When the chat app first opens in the browser, it requires valid connection credentials to connect to Azure SignalR Service. You'll create an HTTP triggered function named `negotiate` in your function app to return this connection information.
121
121
122
122
> [!NOTE]
123
-
> This function must be named *negotiate* as the SignalR client requires an endpoint that ends in `/negotiate`.
123
+
> This function must be named `negotiate` as the SignalR client requires an endpoint that ends in `/negotiate`.
124
124
125
-
1. From the root project folder, create the "negotiate" function from a built-in template with the following command.
125
+
1. From the root project folder, create the `negotiate` function from a built-in template with the following command.
126
126
```bash
127
127
func new --template "SignalR negotiate HTTP trigger" --name negotiate
128
128
```
@@ -166,7 +166,7 @@ When the chat app first opens in the browser, it requires valid connection crede
166
166
167
167
168
168
169
-
1. Open **negotiate/index.js** to view the body of the function.
169
+
1. Open *negotiate/index.js* to view the body of the function.
170
170
171
171
```javascript
172
172
module.exports = async function (context, req, connectionInfo) {
@@ -180,9 +180,9 @@ When the chat app first opens in the browser, it requires valid connection crede
180
180
181
181
### Create a function to send chat messages
182
182
183
-
The web app also requires an HTTP API to send chat messages. You'll create an HTTP triggered function named *sendMessage* that sends messages to all connected clients using SignalR Service.
183
+
The web app also requires an HTTP API to send chat messages. You'll create an HTTP triggered function named `sendMessage` that sends messages to all connected clients using SignalR Service.
184
184
185
-
1. From the root project folder, create an HTTP trigger function named *sendMessage* from the template with the command:
185
+
1. From the root project folder, create an HTTP trigger function named `sendMessage` from the template with the command:
186
186
```bash
187
187
func new --name sendMessage --template "Http trigger"
188
188
```
@@ -215,7 +215,7 @@ The web app also requires an HTTP API to send chat messages. You'll create an HT
215
215
}
216
216
```
217
217
Two changes are made to the original file:
218
-
* Changes the route to `messages` and restricts the HTTP trigger to the **POST** HTTP method.
218
+
* Changes the route to `messages` and restricts the HTTP trigger to the `POST` HTTP method.
219
219
* Adds a SignalR Service output binding that sends a message returned by the function to all clients connected to a SignalR Service hub named `default`.
220
220
221
221
1. Replace the content of *sendMessage/index.js* with the following code:
@@ -241,7 +241,7 @@ The web app also requires an HTTP API to send chat messages. You'll create an HT
241
241
242
242
This function takes the body from the HTTP request and sends it to clients connected to SignalR Service, invoking a function named `newMessage` on each client.
243
243
244
-
The function can read the sender's identity and can accept a *recipient* value in the message body to allow you to send a message privately to a single user. You'll use these functionalities later in the tutorial.
244
+
The function can read the sender's identity and can accept a `recipient` value in the message body to allow you to send a message privately to a single user. You'll use these functionalities later in the tutorial.
245
245
246
246
1. Save the file.
247
247
@@ -254,14 +254,14 @@ The chat application's UI is a simple single-page application (SPA) created with
254
254
1. Create a new folder named *content* in the root directory of your function project.
255
255
1. In the *content* folder, create a new file named *index.html*.
256
256
257
-
1. Copy and paste the content of **[index.html](https://github.com/aspnet/AzureSignalR-samples/blob/da0aca70f490f3d8f4c220d0c88466b6048ebf65/samples/ServerlessChatWithAuth/content/index.html)** to your file. Save the file.
257
+
1. Copy and paste the content of [index.html](https://github.com/aspnet/AzureSignalR-samples/blob/da0aca70f490f3d8f4c220d0c88466b6048ebf65/samples/ServerlessChatWithAuth/content/index.html) to your file. Save the file.
258
258
259
-
1. From the root project folder, create an HTTP trigger function named *index* from the template with the command:
259
+
1. From the root project folder, create an HTTP trigger function named `index` from the template with the command:
260
260
```bash
261
261
func new --name index --template "Http trigger"
262
262
```
263
263
264
-
1. Modify the content of **index/index.js** to the following:
264
+
1. Modify the content of `index/index.js` to the following:
265
265
```js
266
266
const fs = require('fs');
267
267
@@ -279,7 +279,7 @@ The chat application's UI is a simple single-page application (SPA) created with
279
279
```
280
280
The function reads the static web page and returns it to the user.
281
281
282
-
1. Open **index/function.json**, change the **authLevel** of the bindings to **anonymous**. Now the whole file looks like this:
282
+
1. Open *index/function.json*, change the `authLevel` of the bindings to `anonymous`. Now the whole file looks like this:
283
283
```json
284
284
{
285
285
"bindings": [
@@ -321,11 +321,11 @@ You have been running the function app and chat application locally. You'll now
321
321
322
322
### Configure function app for authentication
323
323
324
-
So far, the chat app works anonymously. In Azure, you'll use [App Service Authentication](../app-service/overview-authentication-authorization.md) to authenticate the user. The user ID or username of the authenticated user is passed to the *SignalRConnectionInfo* binding to generate connection information authenticated as the user.
324
+
So far, the chat app works anonymously. In Azure, you'll use [App Service Authentication](../app-service/overview-authentication-authorization.md) to authenticate the user. The user ID or username of the authenticated user is passed to the `SignalRConnectionInfo` binding to generate connection information authenticated as the user.
325
325
326
326
1. Open *negotiate/function.json*.
327
327
328
-
1. Insert a *userId* property to the *SignalRConnectionInfo* binding with value `{headers.x-ms-client-principal-name}`. This value is a [binding expression](../azure-functions/functions-triggers-bindings.md) that sets the user name of the SignalR client to the name of the authenticated user. The binding should now look like this.
328
+
1. Insert a `userId` property to the `SignalRConnectionInfo` binding with value `{headers.x-ms-client-principal-name}`. This value is a [binding expression](../azure-functions/functions-triggers-bindings.md) that sets the user name of the SignalR client to the name of the authenticated user. The binding should now look like this.
329
329
330
330
```json
331
331
{
@@ -347,7 +347,7 @@ Deploy the function app to Azure with the following command:
The *--publish-local-settings* option publishes your local settings from the *local.settings.json* file to Azure, so you don't need to configure them in Azure again.
350
+
The `--publish-local-settings` option publishes your local settings from the *local.settings.json* file to Azure, so you don't need to configure them in Azure again.
0 commit comments