Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Get authorization code with Shopify CLI and Backend API

Get authorization code with Shopify CLI and Backend API

tan_pham1
Shopify Partner
3 0 0

Hello.
I am looking for a way to build an embedded app using Shopify CLI, Shopify App Bridge does not use templates with existing backend server using Golang.

With OAuth, after the user accepts the app installation, verify the installation request
https://shopify.dev/docs/apps/auth/oauth/getting-started#step-2-verify-the-installation-request


Then the App is installed and I successfully enter the APP iframe with parameter

embedded=1&hmac=[HMAC]&host=[HOST]&locale=en-US&session=[SESSION]&shop=[SHOP_NAME].myshopify.com&timestamp=[TIME_STAMP]

My question is that I need an authorization code to verify it by calling the API from my backend server to get the access token.

https://shopify.dev/docs/apps/auth/oauth/getting-started#step-4-validate-authorization-code

But now I'm not sure if I'm missing any steps or if I did something wrong but now I can't get the authorization code. Please help me. Thanks

Replies 2 (2)

Liam
Community Manager
3108 344 899

Hi Tan_pham1,

 

The authorization code is obtained by your app after the user accepts the app installation, and Shopify redirects the user to the redirect URI that you provided during the app setup process. The authorization code will be included in the query parameters of this request to your redirect URI.

Here's an example of what this might look like:

https://your-app.com/auth/callback?code={authorization_code}&hmac=da9d83c171400a41f8db91a950508985&s...

 

As you can see, the authorization code is passed in the code parameter.

 

If you're not seeing this request to your redirect URI or not seeing the code parameter, make sure that you've correctly set your redirect URI in your app settings in the Shopify Partner Dashboard and make sure that your app is correctly handling the initial installation request and redirecting the user to the Shopify authorization prompt.

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

tan_pham1
Shopify Partner
3 0 0

Hello @Liam . Thanks for your response. I still unable to get the code from params to exchange the JWT token. 

I'm using this template for Front-end only https://github.com/Shopify/shopify-frontend-template-react/tree/main

Put all front-end code into `/src` and create `shopify.app.toml` to run entire app with Shopify CLI.

The redirect auth callback generated by shopify CLI

/auth/callback
/auth/shopify/callback
/api/auth/callback
/.shopify/graphiql/auth/callback

So I created similar files as in the redirect callbacks to be able to get code params from the url. But it seems that after installing the app, it doesn't actually go to the redirect pages. I can't log code params in console.

Am I missing something?