-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
AWS Amplify (Events API): Unable to pass authToken with lambda authMode #14124
Comments
For information, 2 days ago i also tested solution that @chrisbonifacio provided, so hydrate the token via the tokenProvider inside the const myTokenProvider: TokenProvider = {
async getTokens({ forceRefresh } = {}) {
if (forceRefresh) {
}
// You can add logic for refreshing tokens if needed
const { data: { session } } = await supabase.auth.getSession();
const accessToken = session?.access_token; // Access the Supabase token
// If token is not available, you might want to handle this case
if (!accessToken) {
throw new Error("Access token not available");
}
// Return the token in a format that AWS expects
return {
accessToken: decodeJWT(accessToken), // Decoding if necessary
idToken: decodeJWT(accessToken), // You can use the same access token for idToken if they are the same
};
},
};
Amplify.configure(
{
API: {
Events: {
endpoint: 'https://example.appsync-api.us-east-1.amazonaws.com/event',
region: 'us-east-1',
defaultAuthMode: 'lambda',
},
},
},
{
Auth: {
tokenProvider: myTokenProvider,
}
}
); Also for more context & debug i've tested via curl, so getting a token manually pass it to my curl command and it return successfully:
|
So after hours of debug i figured out some things that resolve this issue but for some reason i ignore, so for context since i use Supabase authentication, i don't want to have api keys, IAM or others things for authorization but a lambda in my case, so i've created a lambda that use the supabase library to check and it works well, the main issue was when trying to pass the token via the client side using I've tried sending events, and my client receive it, so i maybe misunderstood how does OICD works maybe. The code i've used : Amplify.configure(
{
API: {
Events: {
endpoint: 'https://example.appsync-api.us-east-1.amazonaws.com/event',
region: 'us-east-1',
defaultAuthMode: 'oidc', // Switching from lambda to oidc even if i not configured OIDC on my app sync settings and only have a lambda
},
},
},
{
Auth: {
tokenProvider: myTokenProvider,
}
}
); |
Hi @svatkowski 👋 thanks for updating us on the current status of your troubleshooting this issue. Your mention of using I'm not sure why using Can you try following the guidance from this doc and see if it helps resolve the issue? It sounds like you might've just needed to include a random prefix/suffix and remove it in the lambda handler for the |
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Not applicable
Amplify Version
v6
Amplify Categories
api
Backend
CDK
Environment information
Describe the bug
When using the AWS Amplify Events API (events.connect) with a Supabase-provided token via the authToken parameter, the WebSocket connection fails with the error:
Uncaught (in promise) Error: No auth token specified.
This happens even though the authToken parameter is populated with a valid token retrieved from Supabase's authentication system.
Im also using a JWT Token from supabase
(Note that im using Events API and not GraphQL API)
Expected behavior
The authToken parameter should allow the Amplify SDK to successfully pass the provided Supabase token to the AppSync Events API during the WebSocket connection. This would enable the WebSocket connection to authenticate and function as expected.
when using the AppSync Pub/Sub Editor, the same token works, and the WebSocket connection is established without any issues. However, when passing the token via the Amplify client using the authToken parameter in events.connect, the WebSocket connection fails with the error:
Uncaught (in promise) Error: No auth token specified
Reproduction steps
Setup your AppSync Events API with lambda function, on the client side setup
aws-amplify
, paste the code i've shown and it should throw this errorCode Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: