Skip to content

Commit 4d400a0

Browse files
authored
try update
1 parent cdf3147 commit 4d400a0

File tree

1 file changed

+69
-57
lines changed

1 file changed

+69
-57
lines changed

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

Lines changed: 69 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ In this step-by-step tutorial, you build a chat room with authentication and pri
1919
- [Azure Storage](https://azure.microsoft.com/services/storage/?WT.mc_id=serverlesschatlab-tutorial-antchu): Storage service that Azure Functions requires.
2020
- [Azure App Service](https://azure.microsoft.com/products/app-service/): Service that provides user authentication.
2121

22+
# [Model v4](#tab/nodejs-v4)
23+
24+
> [!NOTE]
25+
> You can get the code mentioned in this article from [GitHub](https://github.com/aspnet/AzureSignalR-samples/blob/90523e17ee5fec184a197b143bb5070bc6d4f312/samples/ServerlessChatWithAuth/v4-model/).
26+
27+
# [Isolated process](#tab/isolated-process)
28+
29+
> [!NOTE]
30+
> You can get the code mentioned in this article from [GitHub](https://github.com/aspnet/AzureSignalR-samples/blob/90523e17ee5fec184a197b143bb5070bc6d4f312/samples/ServerlessChatWithAuth/v3-model/).
31+
32+
---
33+
2234
## Prerequisites
2335

2436
- An Azure account with an active subscription. If you don't have one, you can [create one for free](https://azure.microsoft.com/free/).
@@ -132,86 +144,86 @@ When the chat app first opens in the browser, it requires valid connection crede
132144

133145
1. From the root project folder, create the `negotiate` function from a built-in template by using the following command:
134146

135-
```bash
136-
func new --template "HTTP trigger" --name negotiate
137-
```
147+
```bash
148+
func new --template "HTTP trigger" --name negotiate
149+
```
138150

139151
1. Open _src/functions/negotiate.js_, update the content as follows:
140152

141-
```javascript
142-
const { app, input } = require('@azure/functions');
153+
```javascript
154+
const { app, input } = require('@azure/functions');
143155
144-
const inputSignalR = input.generic({
145-
type: 'signalRConnectionInfo',
146-
name: 'connectionInfo',
147-
hubName: 'default',
148-
connectionStringSetting: 'AzureSignalRConnectionString',
149-
userId: '{query.x-ms-signalr-userid}'
150-
});
156+
const inputSignalR = input.generic({
157+
type: 'signalRConnectionInfo',
158+
name: 'connectionInfo',
159+
hubName: 'default',
160+
connectionStringSetting: 'AzureSignalRConnectionString',
161+
userId: '{query.x-ms-signalr-userid}'
162+
});
151163
152-
app.post('negotiate', {
153-
authLevel: 'function',
154-
handler: (request, context) => {
155-
return { body: JSON.stringify(context.extraInputs.get(inputSignalR)) }
156-
},
157-
route: 'negotiate',
158-
extraInputs: [inputSignalR],
159-
});
160-
```
164+
app.post('negotiate', {
165+
authLevel: 'function',
166+
handler: (request, context) => {
167+
return { body: JSON.stringify(context.extraInputs.get(inputSignalR)) }
168+
},
169+
route: 'negotiate',
170+
extraInputs: [inputSignalR],
171+
});
172+
```
161173
162-
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`.
174+
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`.
163175
164-
This function takes the SignalR connection information from the input binding and returns it to the client in the HTTP response body..
176+
This function takes the SignalR connection information from the input binding and returns it to the client in the HTTP response body..
165177
166-
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.
178+
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.
167179
168180
# [Model v3](#tab/nodejs-v3)
169181
170182
1. Open _negotiate/function.json_ to view the function binding configuration.
171183
172-
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`.
184+
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`.
173185
174-
```json
175-
{
176-
"disabled": false,
177-
"bindings": [
178-
{
179-
"authLevel": "anonymous",
180-
"type": "httpTrigger",
181-
"direction": "in",
182-
"methods": ["post"],
183-
"name": "req",
184-
"route": "negotiate"
185-
},
186-
{
187-
"type": "http",
188-
"direction": "out",
189-
"name": "res"
190-
},
186+
```json
191187
{
192-
"type": "signalRConnectionInfo",
193-
"name": "connectionInfo",
194-
"hubName": "default",
195-
"connectionStringSetting": "AzureSignalRConnectionString",
196-
"direction": "in"
188+
"disabled": false,
189+
"bindings": [
190+
{
191+
"authLevel": "anonymous",
192+
"type": "httpTrigger",
193+
"direction": "in",
194+
"methods": ["post"],
195+
"name": "req",
196+
"route": "negotiate"
197+
},
198+
{
199+
"type": "http",
200+
"direction": "out",
201+
"name": "res"
202+
},
203+
{
204+
"type": "signalRConnectionInfo",
205+
"name": "connectionInfo",
206+
"hubName": "default",
207+
"connectionStringSetting": "AzureSignalRConnectionString",
208+
"direction": "in"
209+
}
210+
]
197211
}
198-
]
199-
}
200-
```
212+
```
201213
202-
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.
214+
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.
203215
204216
1. Close the _negotiate/function.json_ file.
205217
206218
1. Open _negotiate/index.js_ to view the body of the function:
207219
208-
```javascript
209-
module.exports = async function (context, req, connectionInfo) {
210-
context.res.body = connectionInfo;
211-
};
212-
```
220+
```javascript
221+
module.exports = async function (context, req, connectionInfo) {
222+
context.res.body = connectionInfo;
223+
};
224+
```
213225
214-
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.
226+
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.
215227
216228
---
217229

0 commit comments

Comments
 (0)