Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: headerBasedAuth not updating the headers with new values #667

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/aws-appsync-auth-link/__tests__/link/auth-link-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }`

Expand Down
2 changes: 1 addition & 1 deletion packages/aws-appsync-auth-link/src/auth-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

Expand Down