Oauth 错误 invalid_request:授权代码未找到或已被使用“shopify。当我用代码点击 api 时显示这样的错误
Oauth error invalid_request: The authorization code was not found or was already used " shopify. showing error like this when i hit api with code
{
"client_id":"",
"client_secret":"",
"code":""
}
https://test-app.myshopify.com/admin/oauth/access_token
当我点击 api 到此端点以获取离线访问令牌时显示错误,如未找到或已使用授权码。
app.get("/auth/callback", async (req, res) => {
try {
console.log("redirectUrl", req);
const session = await Shopify.Auth.validateAuthCallback(
req,
res,
req.query
);
const host = req.query.host;
const code = req.query.code
app.set(
"active-shopify-shops",
Object.assign(app.get("active-shopify-shops"), {
[session.shop]: session.scope,
})
);
const response = await Shopify.Webhooks.Registry.register({
shop: session.shop,
accessToken: session.accessToken,
topic: "APP_UNINSTALLED",
path: "/webhooks",
});
if (!response["APP_UNINSTALLED"].success) {
console.log(
`Failed to register APP_UNINSTALLED webhook: ${response.result}`
);
}
// Redirect to app with shop parameter upon auth
res.redirect(`/?shop=${session.shop}&host=${host}&code=${code}`);
} catch (e) {
}
}
});
从重定向 URL 获取代码并发送到 iframe 和 post api 从下一个 webapp 我无法从我这边找到代码在哪里使用或者它是后端问题。目前我正在使用应用程序中的访问令牌连接到 shopify。是任何可用于刷新令牌的刷新令牌。我们需要一个永不过期的离线令牌。
终于找到答案了
在服务器文件夹上 -> index.js 有一个名为 USE_ONLINE_TOKENS 的变量,在中间件上设置为 false -> auth.js
const redirectUrl = await Shopify.Auth.beginAuth(
req,
res,
req.query.shop,
"/auth/callback",
false
);
这将创建一个永不过期的离线令牌
{
"client_id":"",
"client_secret":"",
"code":""
}
https://test-app.myshopify.com/admin/oauth/access_token
当我点击 api 到此端点以获取离线访问令牌时显示错误,如未找到或已使用授权码。
app.get("/auth/callback", async (req, res) => {
try {
console.log("redirectUrl", req);
const session = await Shopify.Auth.validateAuthCallback(
req,
res,
req.query
);
const host = req.query.host;
const code = req.query.code
app.set(
"active-shopify-shops",
Object.assign(app.get("active-shopify-shops"), {
[session.shop]: session.scope,
})
);
const response = await Shopify.Webhooks.Registry.register({
shop: session.shop,
accessToken: session.accessToken,
topic: "APP_UNINSTALLED",
path: "/webhooks",
});
if (!response["APP_UNINSTALLED"].success) {
console.log(
`Failed to register APP_UNINSTALLED webhook: ${response.result}`
);
}
// Redirect to app with shop parameter upon auth
res.redirect(`/?shop=${session.shop}&host=${host}&code=${code}`);
} catch (e) {
}
}
});
从重定向 URL 获取代码并发送到 iframe 和 post api 从下一个 webapp 我无法从我这边找到代码在哪里使用或者它是后端问题。目前我正在使用应用程序中的访问令牌连接到 shopify。是任何可用于刷新令牌的刷新令牌。我们需要一个永不过期的离线令牌。
终于找到答案了
在服务器文件夹上 -> index.js 有一个名为 USE_ONLINE_TOKENS 的变量,在中间件上设置为 false -> auth.js
const redirectUrl = await Shopify.Auth.beginAuth(
req,
res,
req.query.shop,
"/auth/callback",
false
);
这将创建一个永不过期的离线令牌