-
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
Appsync Events: Can't pass authToken while using authMode: "lambda" #14062
Comments
Hi @SteveAndreou thanks for raising this issue. While I attempt to reproduce, there's a potential workaround we've been able to use. Can you try adding a You will have to get your OIDC tokens from the You can do so similar to this example: const myTokenProvider: TokenProvider = {
async getTokens({ forceRefresh } = {}) {
if (forceRefresh) {
// try to obtain new tokens if possible
}
const accessTokenString = 'ADD_ACCESS_TOKEN_HERE';
const idTokenString = 'ADD_ID_TOKEN_HERE';
return {
accessToken: decodeJWT(accessTokenString),
idToken: decodeJWT(idTokenString),
};
},
};
Amplify.configure({
API: {
Events: {
endpoint:
'https://URL_FOR_APPSYNC/event',
region: 'us-west-2',
defaultAuthMode: 'lambda',
}
},
}, {
Auth: {
tokenProvider: myTokenProvider
}
}); |
Thanks for the guidance @chrisbonifacio. I managed to authenticate my application using the suggestions you've provided 🙏 |
Update: JS Code Snippet: import { Amplify } from 'aws-amplify';
import { events } from 'aws-amplify/data';
const authToken = "<YOUR_AUTH_TOKEN>";
// Our auth token was not a JWT token, so we override the decodeJWT function with custom one.
function decodeToken(token) {
try {
// Optional: Set payload data
// let payload = {
// exp: 0,
// iss: "",
// aud: "",
// nbf: 0,
// iat: 0,
// scope: "",
// jti: "",
// sub: ""
// }
return {
toString: () => token,
payload: {}, // Optional: Set payload data
};
} catch (err) {
console.log(err)
throw new Error('JWT decode error');
}
}
const myTokenProvider = {
async getTokens({ forceRefresh } = {}) {
if(forceRefresh) {
// Refresh token logic to update authToken
}
return {
accessToken: decodeToken(authToken),
idToken: decodeToken(authToken),
};
},
};
Amplify.configure({
"API": {
"Events": {
"endpoint": "https://<APPSYNC_EVENTS_ENDPOINT_HOST>/event",
"region": "<AWS_REGION>",
"defaultAuthMode": "oidc"
}
}
},
{
"Auth": {
"tokenProvider": myTokenProvider
}
}
);
const channel = await events.connect(`/default/test`); |
@sumeetswn thank you for providing your solution! |
Before opening, please confirm:
JavaScript Framework
React, Next.js
Amplify APIs
GraphQL API
Amplify Version
v6
Amplify Categories
api
Backend
CDK
Environment information
Describe the bug
While using the AWS Amplify provider, I can no provide an authToken while using authMode: "lambda".
I have deployed an AppSync Events API that is configured with an OIDC provider. (Auth0 in this case).
I can provide the Pub/Sub screen in the AppSync Console with a token and successfully connect & receive messages.
I'm now trying to connect my frontend application to the Events API and would like to pass along the token from the session to the server to authenticate the user. Trying to pass any token value (even placeholder strings) at any point is dropped from the provider options once the amplify code runs.
Expected behavior
When I pass a value via the authToken parameter, that value is sent to the server.
Reproduction steps
Following the developer guide will get you there.
https://docs.aws.amazon.com/appsync/latest/eventapi/build-amplify-app.html#configure-amplify-client
Code 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: