-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix api-graphql lambda auth #14177
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
Conversation
e.g. for lambda auth, we need the `authToken`, which is atm not passed down the connect function
bd40060 to
0b82e18
Compare
| options?: EventsOptions, | ||
| ): Promise<EventsChannel> { | ||
| const providerOptions = configure(); | ||
| const configureOptions = configure(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the _connectWebSocket (it is called deeper in the await eventProvider.connect(providerOptions);) method still won't work with non-apiKey auth with this fix. Wouldn't it be better to fix the configure(); helper right away?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think configure(); is called anywhere down the line of await eventProvider.connect(providerOptions);. It always uses the provided providerOptions, also for the _connectWebSocket. All non-apiKey auths add their authentifiation via additionalHeadersFromOptions(options); and here.
I have a (temporary) package published with the changes of this PR. In our internal project, the socket connection is established, we can subscribe to channels and receive events.
|
Facing the same problem with lambda based calls. Would be great to the the solution live! |
|
I believe this issue was fixed by another PR. That change is built to the Thanks! |
|
Thank you and much appreciation for the work you put into this. Glad to have it fixed and if you encounter any issues with this behavior after the next release to latest, please ping me. |
Description of changes
In the connect call of events, the
authTokenis not passed to the subsequent connect calls, resulting in noAuthorizationheader being added, and an error'No auth token specified'thrown.This PR makes sure, the
authTokenis properly dispatched to the subsequent connect calls.Issue #14124
Description of how you validated changes
created a sample vuejs project:
yarn create vueadded 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
get
amplify_outputs.jsonfrom the console, make sure to have"defaultAuthMode": "lambda"setin the vue project, add to main.ts:
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
yarn testpasseschanged oraddedChecklist for repo maintainers
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.