From 1845075c3edc6b8921ebab7299bc91f2d802d6df Mon Sep 17 00:00:00 2001 From: Christopher Harrison Date: Fri, 20 Aug 2021 23:26:06 +0100 Subject: [PATCH 1/2] fix: headerBasedAuth not being able to update the headers with new values --- packages/aws-appsync-auth-link/src/auth-link.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-appsync-auth-link/src/auth-link.ts b/packages/aws-appsync-auth-link/src/auth-link.ts index 8670080d..85c5e00a 100644 --- a/packages/aws-appsync-auth-link/src/auth-link.ts +++ b/packages/aws-appsync-auth-link/src/auth-link.ts @@ -61,8 +61,8 @@ const headerBasedAuth = async ({ header, value }: Headers = { header: '', value: const headerValue = typeof value === 'function' ? await value.call(undefined) : await value; headers = { + ...headers, ...{ [header]: headerValue }, - ...headers }; } From 9454fb6fac6fe713856ab49985209b7bd4b04f0a Mon Sep 17 00:00:00 2001 From: Chris Harrison Date: Sat, 21 Aug 2021 00:48:32 +0100 Subject: [PATCH 2/2] test: adds a test that is breaking before previous commit but passing now --- .../__tests__/link/auth-link-test.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/aws-appsync-auth-link/__tests__/link/auth-link-test.ts b/packages/aws-appsync-auth-link/__tests__/link/auth-link-test.ts index 8f3f24f3..a6597b69 100644 --- a/packages/aws-appsync-auth-link/__tests__/link/auth-link-test.ts +++ b/packages/aws-appsync-auth-link/__tests__/link/auth-link-test.ts @@ -55,6 +55,41 @@ describe("Auth link", () => { execute(testLink, { query }).subscribe({ }) }); + test('Test AMAZON_COGNITO_USER_POOLS authorizer uses result of async jwtToken method', (done) => { + const query = gql`query { someQuery { aField } }` + + const initialiLink = authLink({ + auth: { + type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS, + jwtToken: 'token' + }, + region: 'us-east-1', + url: 'https://xxxxx.appsync-api.amazonaws.com/graphql' + }) + + const link = authLink({ + auth: { + type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS, + jwtToken: 'updated-token' + }, + region: 'us-east-1', + url: 'https://xxxxx.appsync-api.amazonaws.com/graphql' + }) + + + const spyLink = new ApolloLink((operation, forward) => { + const { headers: { Authorization} } = operation.getContext(); + expect(Authorization).toBe('updated-token'); + done(); + + return new Observable(() => {}); + }) + + const testLink = ApolloLink.from([initialiLink, link, spyLink]); + + execute(testLink, { query }).subscribe({ }) + }); + test('Test OPENID_CONNECT authorizer for queries', (done) => { const query = gql`query { someQuery { aField } }`