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 api-graphql lambda auth #14177

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tammoippen
Copy link

Description of changes

In the connect call of events, the authToken is not passed to the subsequent connect calls, resulting in no Authorization header being added, and an error 'No auth token specified' thrown.

const channel = await events.connect('/test/channel', {
      authToken: "TOKEN"
});

This PR makes sure, the authToken is properly dispatched to the subsequent connect calls.

Issue #14124

Description of how you validated changes

  • created a sample vuejs project: yarn create vue

  • added amplify: yarn add aws-amplify.

  • follow the contribution guide to build and link the changes from core and api-graphql

  • setup a aws AppSync Event, lambda function and connect them in the aws console

    def lambda_handler(event, context):
        token: str | None = event.get("authorizationToken")
        headers: dict[str, str] = event.get("requestHeaders", {})
        print(f"{token=} {headers=}")
        return {"isAuthorized": True}
  • get amplify_outputs.json from the console, make sure to have "defaultAuthMode": "lambda" set

  • in the vue project, add to main.ts:

    import { Amplify } from 'aws-amplify';
    import config from './amplify_outputs.json';
    Amplify.configure(config);
  • in the vue project, add to App.vue:

    import { events } from "aws-amplify/data";
    
    async function connect() {
      const channel = await events.connect("/default/*", { authToken: "TOKEN" });
      channel.subscribe({
        next: (d) => {
          console.log("received", d);
        },
        error: (err) => console.error("error", err),
      });
    
    }
  • running the vue app and observe console

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

tammoippen and others added 3 commits January 31, 2025 17:43
@tammoippen tammoippen requested a review from a team as a code owner February 1, 2025 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant