-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
ConnectEventRequest.cs
69 lines (61 loc) · 2.65 KB
/
ConnectEventRequest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace Microsoft.Azure.Functions.Worker
{
/// <summary>
/// Connect event request.
/// </summary>
public sealed class ConnectEventRequest : WebPubSubEventRequest
{
/// <summary>
/// User Claims.
/// </summary>
[JsonPropertyName("claims")]
public IReadOnlyDictionary<string, string[]> Claims { get; set; }
/// <summary>
/// Request query.
/// </summary>
[JsonPropertyName("query")]
public IReadOnlyDictionary<string, string[]> Query { get; set; }
/// <summary>
/// Request headers.
/// </summary>
[JsonPropertyName("headers")]
public IReadOnlyDictionary<string, string[]> Headers { get; set; }
/// <summary>
/// Supported subprotocols.
/// </summary>
[JsonPropertyName("subprotocols")]
public IReadOnlyList<string> Subprotocols { get; set; }
/// <summary>
/// Client certificates.
/// </summary>
[JsonPropertyName("clientCertificates")]
public IReadOnlyList<WebPubSubClientCertificate> ClientCertificates { get; set; }
/// <summary>
/// Create <see cref="ConnectEventResponse"/>.
/// </summary>
/// <param name="userId">Caller userId for current connection.</param>
/// <param name="subprotocol">Subprotocol applied to current connection.</param>
/// <param name="roles">User roles applied to current connection.</param>
/// <param name="groups">Groups applied to current connection.</param>
/// <returns>A connect response to return service.</returns>
public static ConnectEventResponse CreateResponse(string userId, IEnumerable<string> groups, string subprotocol, IEnumerable<string> roles)
{
return new ConnectEventResponse(userId, groups, subprotocol, roles);
}
/// <summary>
/// Create <see cref="EventErrorResponse"/>.
/// Methods works for Function Extensions. And AspNetCore SDK Hub methods can directly throw exception for error cases.
/// </summary>
/// <param name="code"><see cref="WebPubSubErrorCode"/>.</param>
/// <param name="message">Detail error message.</param>
/// <returns>A error response to return caller and will drop connection.</returns>
public static EventErrorResponse CreateErrorResponse(WebPubSubErrorCode code, string message)
{
return new EventErrorResponse(code, message);
}
}
}