I use AWS Lambda, Cognito, and the Gateway API (hosted with Serverless ) to create an API for my web application.
The user authenticates with Cognito and then performs an authenticated API request (template copied from the tutorial
This is very problematic because I see no other way to uniquely identify the user record in my database associated with the Cognito record.
QUESTIONS: Am I missing something? Is there a better way to do this? Is this expected behavior?
Currently, the API is not actually connected to the database. Since our data structure is still moving and the application is far from live, I developed an API that acts the way it integrates with the database and returns data, but this data is simply stored in a JSON file. I will reproduce part of the corresponding code below, in case this is appropriate.
Lambda example to retrieve the current user:
export function getSelf(event, context, callback) { const { cognitoID } = parser(event); const requester = cognitoID && users.find(u => u.cognitoID === cognitoID); try { if (requester) { return callback(null, success(prep(requester, 0))); } else { return authError(callback, `No user found with ID: ${cognitoID}`); } } catch (error) { return uncaughtError(callback, error); } }
This parser is just a utility to get the identifier I want.
A related user entry might look like this:
{ cognitoID: 'us-west-2:605249a8-8fc1-40ed-bf89-23bc74ecc232', id: 'some-slug', email: 'email@whatever.com', firstName: 'John', lastName: 'Jacob Jingleheimer Schmidt', headshot: 'http://fillmurray.com/g/300/300', role: 'admin' },
Cognito JWT. AWS, AWS ( ). Federated Identities. , Cognito User Pools, Federated Identities, AWS AWS. detail.
, , , Federated Identities ( Amazon Cognito), . , , .
Source: https://habr.com/ru/post/1687818/More articles:Failed to connect to renderer after updating Chrome browser to the latest version - selenium-webdriverHow to pull the last of a specific remote branch without having to provide user data? - gitusing libgit2sharp to pull the last from a branch - gitsetting credentials for the first time only (libgit2) - c ++Может ли libgit2sharp полагаться на установленный поставщик глобальной конфигурации git? - libgit2sharpSuddenly he can’t click on the hero: “failed to agree on a key exchange method” - gitКак я могу продвигать функцию, которая возвращает строку с синглонами? - haskellFailed to reconcile key exchange method with Mina deployment - gitPrevent code duplication for different data types (uint16_t / uint32_t) - c ++Creating multiple function columns in Tensorflow - pythonAll Articles