Maintaining persistent connection with python?

Solved
New Member
2 0 0

I'm looking to write my own app with a python backend. I understand we have to get an access token. And it's best to save that token to a session so that whenever the user connects to our app we have the access token for their shop. And lastly; the way I understand it, we get the access token after the user successfully installs our app - and this requires the name of the shop (i.e shopname.myshopify.com).

 

My question is, what if the user logs in from a different computer? They won't have the same session that the access token is stored in. If they don't have that session, we need to make a new one for them. How do we generate a new access token for a new session without repeating the installation process?


I think that the shopify libraries with koa do this all automatically for you; however, I want to use python :/

So if anyone knows how I would go about generating access tokens on demand, without requiring users to go through the installation process again, I would greatly appreciate it!

P.S. current python-shopify libraries either aren't supported anymore, or do not support persistent connections.

0 Likes

Success.

Shopify Staff
Shopify Staff
1489 68 220

I assume you're talking about online access tokens for per-user authentication but correct me if I'm wrong. If the user's session does not currently have an online access token stored in it, you can simply request a new one. Check for its presence, redirect into the oauth flow as you would during install to generate a new one. The user does not have to grant permission if the access scopes have not changed, so you will be immediately redirected from /authorize to your app's redirect URI, where you can exchange the code for a new access token, store it in the user session, and carry on.

 

I hope that makes some sense, but let me know if I'm misunderstanding anything.

 

(I personally store access tokens in my database, but that's just a personal preference for my small scale testing apps).

0 Likes
Highlighted
New Member
2 0 0

Thanks for responding.
I didn't know that when the user goes to the app in their dashboard, they automatically send their shop URL as a query parameter to your app. And I didn't know how to re request the access token without the shop URL, but we just get the shop URL from the initial request.

0 Likes