Skip to content

Commit 920b47d

Browse files
greimelamanueliglesias
authored andcommitted
fix(auth): Remove temporary variables (starting with '@@') before signing (#347)
Fixes #354 This fixes an InvalidSignatureExceptions that occurs when using iamBasedAuthentication and the '@@controlEvents' variable in subscriptions
1 parent 2278942 commit 920b47d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/aws-appsync/src/link/auth-link.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class AuthLink extends ApolloLink {
3636
private link: ApolloLink;
3737

3838
/**
39-
*
39+
*
4040
* @param {*} options
4141
*/
4242
constructor(options) {
@@ -167,7 +167,7 @@ export const authLink = ({ url, region, auth: { type = AUTH_TYPE.NONE, credentia
167167
const formatAsRequest = ({ operationName, variables, query }, options) => {
168168
const body = {
169169
operationName,
170-
variables,
170+
variables: removeTemporaryVariables(variables),
171171
query: print(query)
172172
};
173173

@@ -182,3 +182,15 @@ const formatAsRequest = ({ operationName, variables, query }, options) => {
182182
},
183183
};
184184
}
185+
186+
/**
187+
* Removes all temporary variables (starting with '@@') so that the signature matches the final request.
188+
*/
189+
const removeTemporaryVariables = (variables: any) =>
190+
Object.keys(variables)
191+
.filter(key => !key.startsWith("@@"))
192+
.reduce((acc, key) => {
193+
acc[key] = variables[key];
194+
return acc;
195+
}, {});
196+

0 commit comments

Comments
 (0)