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.
Solved! Go to the solution
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).
|56 seconds ago|
|2 hours ago|
|2 hours ago|
|4 hours ago|