FROM CACHE - en_header

How to get permanent access token for embedded apps.

ajaysaini99
New Member
2 0 0

I have created an embedded node-react app using Shopify-CLI. This is how its server.js file look like this

 

app.prepare().then(async () => {
const server = new Koa();
const router = new Router();
server.keys = [Shopify.Context.API_SECRET_KEY];
server.use(
createShopifyAuth({
async afterAuth(ctx) {
// Access token and shop available in ctx.state.shopify
const { shop, accessToken, scope } = ctx.state.shopify;
const host = ctx.query.host;
ACTIVE_SHOPIFY_SHOPS[shop] = scope;
token = accessToken;
const response = await Shopify.Webhooks.Registry.register({
shop,
accessToken,
path: "/webhooks",
topic: "APP_UNINSTALLED",
webhookHandler: async (topic, shop, body) =>
delete ACTIVE_SHOPIFY_SHOPS[shop],
});

if (!response.success) {
console.log(
`Failed to register APP_UNINSTALLED webhook: ${response.result}`
);
}

// // Redirect to app with shop parameter upon auth

ctx.redirect(`/?shop=${shop}&host=${host}`);
},
})
);

 

I want to get the permanent access token by making a post request to 

 

POST https://{shop}.myshopify.com/admin/oauth/access_token

 

mentioned in documentation.

In your request, {shop} is the name of the merchant's shop and the following parameters must be provided in the request body:

Parameter Description
client_idThe API key for the app, as defined in the Partner Dashboard.
client_secretThe API secret key for the app, as defined in the Partner Dashboard.
codeThe authorization code provided in the redirect.

 

But I don't know where exactly do I have to make this request. 

I am trying to make this request just before ctx.redirect() in above code  but it is throwing an error

InternalServerError: Missing parameter name at 5

I do not know if I am making any mistake in post request or am I making some other mistake.

Its been a week and I am stuck at this.

Could you please help me with this ?

Replies 2 (2)
Yurith
Shopify Partner
10 0 0

Ajaysaini99, did you get to know how to get the token? Also looking into it. Thx.

melika
New Member
2 0 0

Hi!

Have you managed to solve this? I'm facing the same challenge.

Thank you