-
Notifications
You must be signed in to change notification settings - Fork 4
Doplnění dokumentace Keychain proxy do developerské dokumentace #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MatejHamala
wants to merge
2
commits into
gh-pages
Choose a base branch
from
keychain
base: gh-pages
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| --- | ||
| layout: page | ||
| title: "Keychain Proxy" | ||
| category: apps | ||
| date: 2026-03-04 00:00:00 | ||
| active_item: "" | ||
| order: 8 | ||
| --- | ||
|
|
||
| Keychain is a Mergado service that stores and manages user credentials for third-party platforms (e.g. Heureka, Google Analytics, Shopify). It acts as a secure credential store — apps never handle credentials directly, but instead access external services through the Mergado proxy, which attaches the stored credentials automatically. | ||
| This document describes how to use the Keychain proxy in your app. | ||
|
|
||
| ## How It Works | ||
|
|
||
| The app never handles user credentials directly. Instead, the user stores credentials for a third-party service in their Keychain, and the app communicates with that service through the Mergado proxy. | ||
|
|
||
| The flow for every proxied request is: | ||
|
|
||
| 1. The user saves their credentials for a third-party service into their Keychain. | ||
| 2. The app calls the proxy endpoint on Mergado. | ||
| 3. Mergado attaches the stored credentials to the outgoing request. | ||
| 4. The request is forwarded to the target service. | ||
| 5. The response is returned to the app. | ||
|
|
||
| ``` | ||
| App Mergado Proxy Target Service | ||
| | | | | ||
| |-- proxy request --------->| | | ||
| | |-- attach credentials ---->| | ||
| | |<-- response --------------| | ||
| |<-- response --------------| | | ||
| ``` | ||
|
|
||
| ## Using the Proxy in Your App | ||
|
|
||
| The general implementation flow is: | ||
|
|
||
| 1. **Check whether the user has a connection** for the required service. Call the shop info endpoint (see [API documentation](https://api-docs.mergado.com/?api=mergado-api#/Eshops/get_shops__id__info_)) and inspect the returned connections. | ||
| 2. **If no connection exists** — redirect the user to Keychain so they can create one. | ||
| 3. **If a connection exists** — call the appropriate proxy endpoint for the service. The full list of available services and proxy endpoint patterns is in the [API documentation](https://api-docs.mergado.com/?api=mergado-api). | ||
|
|
||
| The app never has access to the user's credentials at any point — the proxy layer handles authentication transparently. | ||
|
|
||
| ## Validating a Connection | ||
|
|
||
| To check the current status of a specific Keychain connection, use the [validate endpoint](https://api-docs.mergado.com/?api=mergado-api#/Eshops/get_shops__id___connection__validate). | ||
|
|
||
| The response contains: | ||
|
|
||
| - `is_valid` — whether the connection is currently functional. Can be `null` when the validation itself cannot be completed (e.g. the external service is experiencing an outage or behaving unexpectedly). | ||
| - `errors` — an array of error objects with an `error` code and a human-readable `message` when `is_valid` is `false`. | ||
|
|
||
| ## Webhooks | ||
|
|
||
| Mergado notifies your app via webhooks when the state of a Keychain connection changes — for example when a user creates or removes a connection. This allows your app to react without polling. | ||
|
|
||
| The relevant hooks are `control.shop.keychain.link_created` and `control.shop.keychain.link_deleted`. Their payloads and full documentation are in the [Hooks documentation](https://mergado.github.io/docs/apps/app-hooks.html). | ||
|
|
||
| **Note:** You can manage your app's hook URL via your app's *Storage* page in [Developers](https://developers.mergado.com). | ||
|
|
||
| ## Error Handling | ||
|
|
||
| Apps should assume that an existing Keychain connection is functional. When a proxy call fails, the recommended approach is: | ||
|
|
||
| 1. **On proxy error** — call the validate endpoint to check the connection status. | ||
| 2. **If the connection is invalid** — store the invalid state locally and stop making proxy calls. Wait for a `control.shop.keychain.link_created` webhook indicating the user has reconnected. | ||
| 3. **Periodic re-check** — as a safety net (in case a webhook is lost or a temporary outage self-resolved), re-validate the connection periodically with a long interval (every few hours or once a day) for some time after the invalidation. | ||
| 4. **Delay user notifications** — notify the user only after a re-validation attempt confirms the connection is still broken, to avoid false alarms caused by transient failures. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Možná by bylo vhodné zmínit v jaké formě ta
expires_atvlastně bude.Obecně, jak nad tím tak přemýšlím, by možná bylo nejlepší se vyvaroval toho, aby se
expires_atprezentovalo jako datetime, a místo toho jej možná spíš udávat jako timestamp<kdy expiruje>.U datetimes se musí (měly by se) řešit timezone - a podle formátu tam buď TZ vůbec třeba (pak se neví, jestli je to UTC, nebo třeba naše evropsko-české letní +2 a zimní +1 - a nedá se to jednoduše odvodit, protože nevíš, jestli to má být UTC, nebo nějaké jiné, nebo tam jen informace o TZ chybí - a to je bordel). Nebo tam ten TZ být může a pak je na programátorech a nebo použitých knihovnách, jestli a jak pak takové datetimes+TZ správně vyhodnocují a porovnávají.
Myslím, že s timezones programátoři "rádi a často" dělají chyby, takže nejlepší by bylo tu variantu úplně eliminovat. Nemít a neřešit timezones, tzn. nemít a neřešit datetimes - a mít políčko
expires_atprostě jako UNIX timestamp. A mít tu ukázaný příklad.