Developer docs
The OAuth install flow, step by step
In short
Redirect the merchant to the consent screen with your client ID, a registered redirect URI and a random state; after they approve, verify the state on your callback and exchange the ten-minute, single-use code at /v1/oauth/token for an offline token. Store the token against store_id. A 401 from the API later means the store uninstalled.
State
Generate a random value per attempt, keep it in the merchant's session on your side, and refuse a callback whose state does not match. It stops another site from completing an install into your app on someone's behalf.
Redirect URIs
Matching is exact: scheme, host, path and query. Register each environment's callback separately (http://localhost is allowed for development).
Codes
A code works once and for ten minutes. If the exchange fails with invalid_grant, send the merchant through the screen again.
Reinstalls
Approving again on a store that already has your app issues a new code, and the new token replaces the old one.
Questions
Can I install without a browser?
On your own test stores, yes, from the developer dashboard. On a merchant's store, the merchant always approves on the consent screen.