Skip to content

Fix oidc authToken not getting passed through to websocket connection open for Events Api #13997

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

Open
wants to merge 4 commits into
base: main
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ const awsAuthTokenHeader = async ({ host }: AWSAppSyncRealTimeAuthInput) => {
};
};

const oidcAuthTokenHeader = async ({ host, additionalCustomHeaders }: AWSAppSyncRealTimeAuthInput) => {
return {
Authorization: additionalCustomHeaders.Authorization,
host,
};
};

const awsRealTimeApiKeyHeader = async ({
apiKey,
host,
Expand Down Expand Up @@ -110,7 +117,7 @@ export const awsRealTimeHeaderBasedAuth = async ({
const headerHandler = {
apiKey: awsRealTimeApiKeyHeader,
iam: awsRealTimeIAMHeader,
oidc: awsAuthTokenHeader,
oidc: oidcAuthTokenHeader,
Comment on lines -113 to +120
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks the expected behavior for OIDC auth for both Events and GraphQL subscriptions. By default, this auth mode is meant to work with the OIDC configuration provided through Amplify Backend and sign in/sign out handled via Amplify Auth. When configured this way, we automatically extract the OIDC access token from the currently signed in user in the awsAuthTokenHeader function and pass it through to the subscription auth token. This functionality must remain intact.

That being said, I agree that we should allow a fallback to a manually-managed authToken passed in through the client's public API. I think we can do that by conditionally calling either the existing customAuthHeader or awsAuthTokenHeader depending on whether an explicit authToken was specified at the client call site.

userPool: awsAuthTokenHeader,
lambda: customAuthHeader,
none: customAuthHeader,
Expand Down
8 changes: 8 additions & 0 deletions packages/api-graphql/src/internals/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ async function connect(
providerOptions.authenticationType,
);

if (options?.authToken) {
providerOptions.authToken = options.authToken
}

await eventProvider.connect(providerOptions);

let _subscription: Subscription;
Expand All @@ -62,6 +66,10 @@ async function connect(
subscribeOptions.authenticationType,
);

if (subOptions?.authToken) {
subscribeOptions.authToken = subOptions.authToken
}

_subscription = eventProvider
.subscribe(subscribeOptions)
.subscribe(observer);
Expand Down