garettB / shopify-flask-example

A simple Shopify app created using Flask and Python
Other
231 stars 66 forks source link

Authenticate loop #6

Open mrdbstn opened 3 years ago

mrdbstn commented 3 years ago

Hey there,

Thanks for providing us with this code it's really helpful to try and understand working with Shopify.

I am trying to add a get_products() function to shopify_client.py. It's identical to get_shop();

def get_products(self) -> dict:
        call_path = 'products.json'
        method = 'GET'
        shop_response = self.authenticated_shopify_call(call_path=call_path, method=method)

        if not shop_response:
            return 'failed request'

        return shop_response['products']

To make this work, I added the required scope 'read_products' to ACCESS_SCOPES in server.py, but now when I try to access the app, it's stuck in an infinite authentication loop, as it's not getting the access token

This actually happens every time when you restart the server, but this wasn't an issue with just the write_script_tags scope, since it would load properly if you stopped loading the page (by simply using the browser button in the top left) and then refreshing the page. This however doesn't work with more scopes added.

I don't if saving the access token in a database, instead of requesting it every time we restart the server, would do anything, as it seems it's unable to get it in the first place when requesting more scopes.

Let me know what you think of this. Thanks in advance!

garettB commented 3 years ago

Hi,

If it only happens with that one scope (I would recommend trying with other scopes if you haven't) then it could be an additional requirement by Shopify possibly? Perhaps with the app setup? Sorry, I am not going to be much use for the foreseeable to help troubleshoot, but hopefully you can solve the issue or maybe someone in the Shopify forum can help?