shopify - 为 Shopify 公共应用生成在线和离线访问令牌
问题描述
Shopify 的样板应用程序这样做是为了生成访问令牌(默认为在线访问模式)
server.use(
createShopifyAuth({
apiKey: SHOPIFY_API_KEY,
secret: SHOPIFY_API_SECRET,
scopes: [SCOPES],
async afterAuth(ctx) {
// Access token and shop available in ctx.state.shopify
const { shop } = ctx.state.shopify;
// Redirect to app with shop parameter upon auth
ctx.redirect(`/?shop=${shop}`);
},
})
);
就我而言,我想要在线和离线令牌
- 离线令牌将生成一次(如果商店未添加到我的数据库中),accessMode 设置为离线并推送到数据库。
- 当前登录用户的在线令牌。
有没有办法在一个流程中生成两个令牌?
下面这行不通。Koa 响应 404 not found
server.use(function (ctx, next) {
console.log(JSON.stringify(ctx.request.query.shop))
if (ctx.request && ctx.request.query && ctx.request.query.shop) {
if (isStoreAlreadyAdded(ctx.request.query.shop) === 0) {
createShopifyAuth({
apiKey: SHOPIFY_API_KEY,
secret: SHOPIFY_API_SECRET,
scopes: [SCOPES],
accessMode: 'offline',
async afterAuth(ctx) {
// Access token and shop available in ctx.state.shopify
const { shop } = ctx.state.shopify;
// Redirect to app with shop parameter upon auth
ctx.redirect(`/?shop=${shop}`);
},
})
}
} else {
shopifyAuth({
afterAuth(ctx) {
const {shop, accessToken} = ctx.state.shopify;
console.log('We did it!', accessToken);
ctx.redirect(`/?shop=${shop}`);
},
})
}
});
解决方案
推荐阅读
- paypal - 如何捕获paypal webhook?
- pandas - 如何从 Sklearn CountVectorizer 中删除频繁/不频繁的特征?
- c++ - 在 myVector 类中重载运算符 + 时出错
- powershell - Powershell 匹配文件名并追加
- java - 如果存在更改,则 Maven 安装
- kframework - 在 K 中遍历评估上下文?
- mysql - 从 Access VBA 打印到 Dymo LabelWriter 450
- lua - lua匹配重复模式
- python - TensorFlow 和随机森林模型的评估
- python - 我的代码没有按国家/地区对我的数据框进行分组有什么原因吗?