Improve "Private App" API usage
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia da src/Clients/Rest.php intorno all’header del token di accesso e segui Context::initialize e i relativi controlli di inizializzazione. Conferma il flusso diretto desiderato Rest($domain, $storeApiToken), inclusi i valori predefiniti elencati e il comportamento del logging, quindi verifica che il comportamento esistente dell’API e i test continuino a superare i controlli.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Overview/summary
Currently using this library when connecting to a private app is confusing.
It takes quite a long time to work out what you are doing, when it feels like it could be really simple.
Motivation
In our usecase, we only want to consume the Shopify admin api via REST, with a private app access token.
Currently to do that you have to have the following code:
Context::initialize(
'xxx', // Not used
'yyy', // Not used
'read_orders, write_orders', // Not used
'http://localhost', // Not used
new FileSessionStorage('/tmp/php_sessions'), // Not used
'latest',
false, // Not used
false, // Needs to (incorrectly) be set to false
);
$rest = new Rest($domain, $storeApiToken);
This is not helped by the fact that there is a bug on this line:
https://github.com/Shopify/shopify-php-api/blob/main/src/Clients/Rest.php#L46
So you actually have to Context::initialize with "privateApp" to to false, so it uses the access token not the secret key.
$headers[HttpHeaders::X_SHOPIFY_ACCESS_TOKEN] =
Context::$IS_PRIVATE_APP ? Context::$API_SECRET_KEY : $this->accessToken;
There is barely any point in having to call Context::initialize, the only reason for doing it is to:
- Set Context::$IS_INITIALIZED (to prevent an exception)
- Default Context::$HTTP_CLIENT_FACTORY = new HttpClientFactory();
In an ideal situation I would just need to do this:
$rest = new Rest($domain, $storeApiToken);
Possible Improvements
- Remove the need to call Context::initialize
- Default the API version to 'unstable'
- Default the initialization of $HTTP_CLIENT_FACTORY if null
- Don't throw an exception during log if not initialized
Happy to contribute these changes, if you are welcome to receive them.
- Lingua principale
- PHP
- Stelle
- 473
- Fork
- 193
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Issue simili
-
maintenance
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
hawk-digital-environments/HAWKI#443 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
crazy-goat/rabbit-stream#799 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Code Quality
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Automattic/safe-publish#708 ·
I maintainer di solito rispondono entro 1 giorno