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

Access request headers in IAM-authorized subscription endpoints #721

Open
ghost opened this issue May 25, 2022 · 2 comments
Open

Access request headers in IAM-authorized subscription endpoints #721

ghost opened this issue May 25, 2022 · 2 comments
Labels
feature-request Have an idea, share it with us! p5

Comments

@ghost
Copy link

ghost commented May 25, 2022

Do you want to request a feature or report a bug?

Feature

What is the current behavior?

I have an interesting use-case where I need to pass along additional request headers to a subscription endpoint to trigger some logic in the corresponding request resolver. My subscription uses IAM auth, which results in the following payload:

{
  id: "..."
  payload: {…}
  data: "..."
  extensions: {
    authorization: {
      accept: "application/json, text/javascript", 
      content-encoding: "amz-1.0"
      ...all my custom headers end up here...
    }
  }
  type: "start"
}

While my custom headers do get sent, they appear inaccessible once the resolver context is built and supplied to my resolver template. Instead, request headers are only available from the SigV4 headers sent in with the query string ?header="..."

Modifying AppSyncRealTimeSubscriptionHandshakeLink._awsRealTimeIAMHeader to include custom headers would resolve this problem, iff this is a reasonable use-case and I'm not missing some other avenue for accessing my headers.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

What is the expected behavior?

Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions?

@ghost
Copy link
Author

ghost commented May 25, 2022

I'd also be willing to open a pull request for this change.

@iartemiev iartemiev added feature-request Have an idea, share it with us! p5 labels Feb 13, 2023
@sis-dk
Copy link

sis-dk commented Apr 2, 2023

Would this help?

import { setContext } from '@apollo/client/link/context'
const link = ApolloLink.from([
    setContext((request, previousContext) => {
      return {
        headers: {
          ...previousContext.headers,
          //Your own headers here
        }
      }
    }),
    //Other links here
])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Have an idea, share it with us! p5
Projects
None yet
Development

No branches or pull requests

2 participants