Re: Test app on development store no code

Solved

How to test an app on a development store without a code?

JOSEPH_ANDERSO1
Shopify Partner
45 0 7

Hi,

 

I am trying to test installing my app on my development store.

 

When I go to test app on development store, I am redirected back to my site. The parameter code is missing. This means I cannot obtain an access token, then send the user to Shopify to pay. Here is the URL that I receive:

 

hmac=X&host=Y&shop=myshop.myshopify.com&timestamp=1701874522

 

How do I get a code, so I can make an access token?

Accepted Solution (1)

reastful
Shopify Partner
2 1 1

This is an accepted solution.

Hi,

 

The auth process includes few steps:

 

At first you need to verify the installation request from Shopify (you are here)

 

Then you need to redirect user back to Shopify so he can confirm it and give you an access to his data

 

Then he will be redirected to your site again and you will need to obtain an access token from the oauth server

 

The whole process is described here, please follow it step by step and you will make it

 

https://shopify.dev/docs/apps/auth/oauth/getting-started

View solution in original post

Replies 8 (8)

reastful
Shopify Partner
2 1 1

This is an accepted solution.

Hi,

 

The auth process includes few steps:

 

At first you need to verify the installation request from Shopify (you are here)

 

Then you need to redirect user back to Shopify so he can confirm it and give you an access to his data

 

Then he will be redirected to your site again and you will need to obtain an access token from the oauth server

 

The whole process is described here, please follow it step by step and you will make it

 

https://shopify.dev/docs/apps/auth/oauth/getting-started

poik
Shopify Partner
2 0 0

Hi this does not address the issue. The problem is when it is redirected to our site again, the code parameter is missing thus unable to request for the access token. Any solution for this ?

poik
Shopify Partner
2 0 0

hi did you manage to get the working solution for this ?

travisehead3800
New Member
5 0 0

Hi Were you able to find a working solution for this?

JOSEPH_ANDERSO1
Shopify Partner
45 0 7

Hi,

 

You need to redirect the user back to the store. If my store was jmatestshop.myshopify.com, here is the URL I would use:

 

C#:

 

public string GetAuthorizationURL(string[] scope, string? redirectUrl = null)
{
var authURL = new StringBuilder();

authURL.AppendFormat("http://{0}.myshopify.com/admin/oauth/authorize", this._shopName);
authURL.AppendFormat("?client_id={0}", this._apiKey);

if (scope != null && scope.Length > 0)
{
string commaSeperatedScope = String.Join(",", scope);
if (!String.IsNullOrEmpty(commaSeperatedScope))
authURL.AppendFormat("&scope={0}", HttpUtility.UrlEncode(commaSeperatedScope));
}

if (redirectUrl != null && redirectUrl.Length > 0)
{
authURL.AppendFormat("&redirect_uri={0}", HttpUtility.UrlEncode(redirectUrl));
}

return authURL.ToString();
}

 

Once the user accepts the install, send the user back to your page:

 

[HttpPost("ShopifyAuthCallback")]
public async Task<IActionResult> ShopifyAuthCallback()
{
ShopifyPaymentModel shopifyPaymentModel = new ShopifyPaymentModel();
string connexUserId = User.GetConnexUserId();
string jsonString;
using (StreamReader sr = new StreamReader(Request.Body, Encoding.UTF8))
{
jsonString = sr.ReadToEnd();
}

var ShopifyInstallOAuth = JsonConvert.DeserializeObject<ShopifyInstall>(jsonString);

 

//ShopifyInstallOAuth will have the code. Exchange for an access token.

 

I could add some code here, if necessary:

 

https://github.com/jmawebtech/Shopify-C--GraphQL

}

travisehead3800
New Member
5 0 0

Thanks for the detailed explanation and code sample! This approach makes sense. I'll implement the redirection using the GetAuthorizationURL method and handle the callback using the ShopifyAuthCallback method. The GitHub link for additional code is a great resource—appreciate it! Let me know if you have more tips for setting this up.

JOSEPH_ANDERSO1
Shopify Partner
45 0 7

Hi,

 

Sure, please reply if you have more questions. Are you implementing the Shopify billing API? If so, you must redirect the user to Shopify to pay, then pair Shopify with your software. OAuth will only work, if Shopify approves you for their app store.

 

After you get the code and get the access token, send the user here:

 

https://shopify.dev/docs/api/admin-rest/2024-10/resources/recurringapplicationcharge#post-recurring-...

 

Once the user approves, there is a parameter called redirect_url. Send the user to a payment success page on your site.

travisehead3800
New Member
5 0 0

Thank you for the details! Yes, I am working with the Shopify Billing API, and your explanation helps clarify the flow. I'll ensure the user is redirected to Shopify for payment and then paired with my software. After obtaining the access token, I'll integrate the redirect_url to guide users to a payment success page on my site for a seamless experience.

Appreciate your guidance—let me know if there's anything else I should watch out for!