- Не могли бы вы объяснить, как и где в коде link_token возвращает общедоступный токен?
app.post('/api/create_link_token', async function (request, response) {
const configs = {
user: {
// This should correspond to a unique id for the current user.
client_user_id: 'user-id',
},
client_name: 'Plaid Quickstart',
products: PLAID_PRODUCTS,
country_codes: PLAID_COUNTRY_CODES,
language: 'en',
};
if (PLAID_REDIRECT_URI !== '') {
configs.redirect_uri = PLAID_REDIRECT_URI;
}
if (PLAID_ANDROID_PACKAGE_NAME !== '') {
configs.android_package_name = PLAID_ANDROID_PACKAGE_NAME;
}
try {
const createTokenResponse = await client.linkTokenCreate(configs);
console.log('Create Token response below')
prettyPrintResponse(createTokenResponse.data);
response.json(createTokenResponse.data);
} catch (error) {
prettyPrintResponse(error);
return response.json(formatError(error.response));
}
});
Согласно Plaid Docs: Конечная точка /link/token/create создает link_token, который требуется в качестве параметра при инициализации Link. После инициализации Link он возвращает public_token, который затем можно обменять на access_token через /item/public_token/exchange в рамках основного потока Link.
- Как PUBLIC_TOKEN= request.body.public_token? Как публичный токен попал в request.body?
app.post('/api/set_access_token', async function (request, response, next) {
// Im inquiring about the line right below//
PUBLIC_TOKEN = request.body.public_token;
console.log("after", PUBLIC_TOKEN)
try {
const tokenResponse = await client.itemPublicTokenExchange({
public_token: PUBLIC_TOKEN,
});
prettyPrintResponse(tokenResponse.data);
ACCESS_TOKEN = tokenResponse.data.access_token;
ITEM_ID = tokenResponse.data.item_id;
response.json({
access_token: ACCESS_TOKEN,
item_id: ITEM_ID,
error: null,
});
} catch (error) {
prettyPrintResponse(error);
return response.json(formatError(error.response));
}
});