Skip to content

Commit 6043861

Browse files
committed
Fix for Wrong struct for IoTCustomAuthorizerRequest aws#400
1 parent 1cb90e0 commit 6043861

File tree

3 files changed

+59
-30
lines changed

3 files changed

+59
-30
lines changed

events/iot.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ package events
22

33
// IoTCustomAuthorizerRequest contains data coming in to a custom IoT device gateway authorizer function.
44
type IoTCustomAuthorizerRequest struct {
5-
HTTPContext *IoTHTTPContext `json:"httpContext,omitempty"`
6-
MQTTContext *IoTMQTTContext `json:"mqttContext,omitempty"`
7-
TLSContext *IoTTLSContext `json:"tlsContext,omitempty"`
8-
AuthorizationToken string `json:"token"`
9-
TokenSignature string `json:"tokenSignature"`
5+
Token string `json:"token"`
6+
SignatureVerified bool `json:"signatureVerified"` //whether the device gateway has validated the signature
7+
Protocols []string `json:"protocols"` //can include "tls", "mqtt", or "http"
8+
ProtocolData IoTCustomAuthorizerProtocolData `json:"protocolData"`
9+
ConnectionMetadata IoTCustomAuthorizerMetadata `json:"connectionMetadata"`
10+
}
11+
12+
type IoTCustomAuthorizerProtocolData struct {
13+
HTTP *IoTHTTPContext `json:"http,omitempty"`
14+
MQTT *IoTMQTTContext `json:"mqtt,omitempty"`
15+
TLS *IoTTLSContext `json:"tls,omitempty"`
1016
}
1117

1218
type IoTHTTPContext struct {
@@ -16,19 +22,23 @@ type IoTHTTPContext struct {
1622

1723
type IoTMQTTContext struct {
1824
ClientID string `json:"clientId"`
19-
Password []byte `json:"password"`
25+
Password string `json:"password"` //base64-encoded string
2026
Username string `json:"username"`
2127
}
2228

2329
type IoTTLSContext struct {
2430
ServerName string `json:"serverName"`
2531
}
2632

33+
type IoTCustomAuthorizerMetadata struct {
34+
ID string `json:"id"` //UUID. The connection ID
35+
}
36+
2737
// IoTCustomAuthorizerResponse represents the expected format of an IoT device gateway authorization response.
2838
type IoTCustomAuthorizerResponse struct {
29-
IsAuthenticated bool `json:"isAuthenticated"`
30-
PrincipalID string `json:"principalId"`
31-
DisconnectAfterInSeconds int32 `json:"disconnectAfterInSeconds"`
32-
RefreshAfterInSeconds int32 `json:"refreshAfterInSeconds"`
33-
PolicyDocuments []string `json:"policyDocuments"`
39+
IsAuthenticated bool `json:"isAuthenticated"`
40+
PrincipalID string `json:"principalId"`
41+
DisconnectAfterInSeconds int32 `json:"disconnectAfterInSeconds"`
42+
RefreshAfterInSeconds int32 `json:"refreshAfterInSeconds"`
43+
PolicyDocuments []APIGatewayCustomAuthorizerPolicy `json:"policyDocuments"`
3444
}
Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
{
2-
"httpContext": {
3-
"headers": {
4-
"Accept-Language" : "en"
2+
"token": "someToken",
3+
"signatureVerified": true,
4+
"protocols": ["tls", "http", "mqtt"],
5+
"protocolData": {
6+
"http": {
7+
"headers": {
8+
"Accept-Language" : "en"
9+
},
10+
"queryString": "abc"
511
},
6-
"queryString": "abc"
7-
},
8-
"mqttContext": {
9-
"clientId": "someclient",
10-
"password": "aslkfjwoeiuwekrujwlrueowieurowieurowiuerwleuroiwueroiwueroiuweoriuweoriuwoeiruwoeiur",
11-
"username": "thebestuser"
12-
},
13-
"tlsContext": {
14-
"serverName": "server.stuff.com"
12+
"mqtt": {
13+
"clientId": "someclient",
14+
"password": "aslkfjwoeiuwekrujwlrueowieurowieurowiuerwleuroiwueroiwueroiuweoriuweoriuwoeiruwoeiur",
15+
"username": "thebestuser"
16+
},
17+
"tls": {
18+
"serverName": "server.stuff.com"
19+
}
1520
},
16-
"token": "someToken",
17-
"tokenSignature": "somelongtokensignature"
21+
"connectionMetadata": {
22+
"id": "123e4567-e89b-12d3-a456-426614174000"
23+
}
1824
}
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
{
22
"isAuthenticated":true,
3-
"principalId": "xxxxxxxx",
4-
"disconnectAfterInSeconds": 86400,
5-
"refreshAfterInSeconds": 300,
6-
"policyDocuments": [
7-
"{ \"Version\": \"2012-10-17\", \"Statement\": [ { \"Action\": [\"iot:Subscribe\"], \"Effect\": \"Allow\", \"Resource\": [\"*\"] } ] }"
3+
"principalId":"xxxxxxxx",
4+
"disconnectAfterInSeconds":86400,
5+
"refreshAfterInSeconds":300,
6+
"policyDocuments":[
7+
{
8+
"Version":"2012-10-17",
9+
"Statement":[
10+
{
11+
"Action":[
12+
"iot:Subscribe"
13+
],
14+
"Effect":"Allow",
15+
"Resource":[
16+
"*"
17+
]
18+
}
19+
]
20+
}
821
]
922
}

0 commit comments

Comments
 (0)