forked from aws/aws-lambda-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
APIGatewayCustomAuthorizerContext.cs
158 lines (146 loc) · 4.61 KB
/
APIGatewayCustomAuthorizerContext.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
namespace Amazon.Lambda.APIGatewayEvents
{
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
#if NETSTANDARD_2_0
using Newtonsoft.Json.Linq;
#else
using System.Text.Json;
#endif
/// <summary>
/// An object representing the expected format of an API Gateway custom authorizer response.
/// </summary>
[DataContract]
public class APIGatewayCustomAuthorizerContext : Dictionary<string, object>
{
/// <summary>
/// Gets or sets the 'principalId' property.
/// </summary>
[Obsolete("This property is obsolete. Code should be updated to use the string index property like authorizer[\"principalId\"]")]
public string PrincipalId
{
get
{
object value;
if (this.TryGetValue("principalId", out value))
return value.ToString();
return null;
}
set
{
this["principalId"] = value;
}
}
/// <summary>
/// Gets or sets the 'stringKey' property.
/// </summary>
[Obsolete("This property is obsolete. Code should be updated to use the string index property like authorizer[\"stringKey\"]")]
public string StringKey
{
get
{
object value;
if (this.TryGetValue("stringKey", out value))
return value.ToString();
return null;
}
set
{
this["stringKey"] = value;
}
}
/// <summary>
/// Gets or sets the 'numKey' property.
/// </summary>
[Obsolete("This property is obsolete. Code should be updated to use the string index property like authorizer[\"numKey\"]")]
public int? NumKey
{
get
{
object value;
if (this.TryGetValue("numKey", out value))
{
int i;
if (int.TryParse(value?.ToString(), out i))
{
return i;
}
}
return null;
}
set
{
this["numKey"] = value;
}
}
/// <summary>
/// Gets or sets the 'boolKey' property.
/// </summary>
[Obsolete("This property is obsolete. Code should be updated to use the string index property like authorizer[\"boolKey\"]")]
public bool? BoolKey
{
get
{
object value;
if (this.TryGetValue("boolKey", out value))
{
bool b;
if(bool.TryParse(value?.ToString(), out b))
{
return b;
}
}
return null;
}
set
{
this["boolKey"] = value;
}
}
Dictionary<string, string> _claims;
/// <summary>
/// Gets or sets the claims coming from Cognito
/// </summary>
public Dictionary<string, string> Claims
{
get
{
if(_claims == null)
{
_claims = new Dictionary<string, string>();
object value;
if(this.TryGetValue("claims", out value))
{
#if NETSTANDARD_2_0
JObject jsonClaims = value as JObject;
if (jsonClaims != null)
{
foreach (JProperty property in jsonClaims.Properties())
{
_claims[property.Name] = property.Value?.ToString();
}
}
#else
if(value is JsonElement jsonClaims)
{
foreach(JsonProperty property in jsonClaims.EnumerateObject())
{
if(property.Value.ValueKind == JsonValueKind.String)
{
_claims[property.Name] = property.Value.GetString();
}
}
}
#endif
}
}
return _claims;
}
set
{
this._claims = value;
}
}
}
}