Skip to content

Commit a02d6f0

Browse files
authored
update
1 parent 7afdff1 commit a02d6f0

File tree

1 file changed

+70
-70
lines changed

1 file changed

+70
-70
lines changed

articles/azure-signalr/signalr-tutorial-authenticate-azure-functions.md

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -126,90 +126,90 @@ When the chat app first opens in the browser, it requires valid connection crede
126126
> [!NOTE]
127127
> This function must be named `negotiate` because the SignalR client requires an endpoint that ends in `/negotiate`.
128128
129-
# [Model v4](#tab/nodejs-v4)
130-
131-
1. From the root project folder, create the `negotiate` function from a built-in template by using the following command:
132-
133-
```bash
134-
func new --template "HTTP trigger" --name negotiate
135-
```
136-
137-
1. Open _src/functions/negotiate.js_, update the content as follows:
138-
139-
```javascript
140-
const { app, input } = require('@azure/functions');
129+
# [Model v4](#tab/nodejs-v4)
141130

142-
const inputSignalR = input.generic({
143-
type: 'signalRConnectionInfo',
144-
name: 'connectionInfo',
145-
hubName: 'default',
146-
connectionStringSetting: 'AzureSignalRConnectionString',
147-
userId: '{query.x-ms-signalr-userid}'
148-
});
131+
1. From the root project folder, create the `negotiate` function from a built-in template by using the following command:
149132

150-
app.post('negotiate', {
151-
authLevel: 'function',
152-
handler: (request, context) => {
153-
return { body: JSON.stringify(context.extraInputs.get(inputSignalR)) }
154-
},
155-
route: 'negotiate',
156-
extraInputs: [inputSignalR],
157-
});
158-
```
133+
```bash
134+
func new --template "HTTP trigger" --name negotiate
135+
```
159136

160-
The function contains an HTTP trigger binding to receive requests from SignalR clients. The function also contains a SignalR input binding to generate valid credentials for a client to connect to an Azure SignalR Service hub named `default`.
137+
1. Open _src/functions/negotiate.js_, update the content as follows:
161138

162-
This function takes the SignalR connection information from the input binding and returns it to the client in the HTTP response body..
139+
```javascript
140+
const { app, input } = require('@azure/functions');
141+
142+
const inputSignalR = input.generic({
143+
type: 'signalRConnectionInfo',
144+
name: 'connectionInfo',
145+
hubName: 'default',
146+
connectionStringSetting: 'AzureSignalRConnectionString',
147+
userId: '{query.x-ms-signalr-userid}'
148+
});
149+
150+
app.post('negotiate', {
151+
authLevel: 'function',
152+
handler: (request, context) => {
153+
return { body: JSON.stringify(context.extraInputs.get(inputSignalR)) }
154+
},
155+
route: 'negotiate',
156+
extraInputs: [inputSignalR],
157+
});
158+
```
163159
164-
There's no `userId` property in the `signalRConnectionInfo` binding for local development. You'll add it later to set the username of a SignalR connection when you deploy the function app to Azure.
160+
The function contains an HTTP trigger binding to receive requests from SignalR clients. The function also contains a SignalR input binding to generate valid credentials for a client to connect to an Azure SignalR Service hub named `default`.
165161
166-
# [Model v3](#tab/nodejs-v3)
162+
This function takes the SignalR connection information from the input binding and returns it to the client in the HTTP response body..
167163
168-
1. Open _negotiate/function.json_ to view the function binding configuration.
164+
There's no `userId` property in the `signalRConnectionInfo` binding for local development. You'll add it later to set the username of a SignalR connection when you deploy the function app to Azure.
169165
170-
The function contains an HTTP trigger binding to receive requests from SignalR clients. The function also contains a SignalR input binding to generate valid credentials for a client to connect to an Azure SignalR Service hub named `default`.
166+
# [Model v3](#tab/nodejs-v3)
171167
172-
```json
173-
{
174-
"disabled": false,
175-
"bindings": [
176-
{
177-
"authLevel": "anonymous",
178-
"type": "httpTrigger",
179-
"direction": "in",
180-
"methods": ["post"],
181-
"name": "req",
182-
"route": "negotiate"
183-
},
184-
{
185-
"type": "http",
186-
"direction": "out",
187-
"name": "res"
188-
},
189-
{
190-
"type": "signalRConnectionInfo",
191-
"name": "connectionInfo",
192-
"hubName": "default",
193-
"connectionStringSetting": "AzureSignalRConnectionString",
194-
"direction": "in"
195-
}
196-
]
197-
}
198-
```
168+
1. Open _negotiate/function.json_ to view the function binding configuration.
169+
170+
The function contains an HTTP trigger binding to receive requests from SignalR clients. The function also contains a SignalR input binding to generate valid credentials for a client to connect to an Azure SignalR Service hub named `default`.
171+
172+
```json
173+
{
174+
"disabled": false,
175+
"bindings": [
176+
{
177+
"authLevel": "anonymous",
178+
"type": "httpTrigger",
179+
"direction": "in",
180+
"methods": ["post"],
181+
"name": "req",
182+
"route": "negotiate"
183+
},
184+
{
185+
"type": "http",
186+
"direction": "out",
187+
"name": "res"
188+
},
189+
{
190+
"type": "signalRConnectionInfo",
191+
"name": "connectionInfo",
192+
"hubName": "default",
193+
"connectionStringSetting": "AzureSignalRConnectionString",
194+
"direction": "in"
195+
}
196+
]
197+
}
198+
```
199199
200-
There's no `userId` property in the `signalRConnectionInfo` binding for local development. You'll add it later to set the username of a SignalR connection when you deploy the function app to Azure.
200+
There's no `userId` property in the `signalRConnectionInfo` binding for local development. You'll add it later to set the username of a SignalR connection when you deploy the function app to Azure.
201201
202-
1. Close the _negotiate/function.json_ file.
202+
1. Close the _negotiate/function.json_ file.
203203
204-
1. Open _negotiate/index.js_ to view the body of the function:
204+
1. Open _negotiate/index.js_ to view the body of the function:
205205
206-
```javascript
207-
module.exports = async function (context, req, connectionInfo) {
208-
context.res.body = connectionInfo;
209-
};
210-
```
206+
```javascript
207+
module.exports = async function (context, req, connectionInfo) {
208+
context.res.body = connectionInfo;
209+
};
210+
```
211211
212-
This function takes the SignalR connection information from the input binding and returns it to the client in the HTTP response body. The SignalR client uses this information to connect to the Azure SignalR Service instance.
212+
This function takes the SignalR connection information from the input binding and returns it to the client in the HTTP response body. The SignalR client uses this information to connect to the Azure SignalR Service instance.
213213
214214
[Having issues? Let us know.](https://aka.ms/asrs/qsauth)
215215

0 commit comments

Comments
 (0)