Skip to content

Commit

Permalink
feat: use access_token instead of basic auth and update config to ref…
Browse files Browse the repository at this point in the history
…lect this
  • Loading branch information
Razorsheep committed Nov 11, 2022
1 parent 82df528 commit 6ed040f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
9 changes: 2 additions & 7 deletions config/shopify.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@
'credentials' => [

/*
* The API key from private app credentials.
* The API access token from the private app.
*/
'api_key' => env('SHOPIFY_API_KEY', ''),

/*
* The password from private app credentials.
*/
'password' => env('SHOPIFY_PASSWORD', ''),
'api_access_token' => env('SHOPIFY_API_ACCESS_TOKEN', ''),

/*
* The shopify domain for your shop.
Expand Down
6 changes: 2 additions & 4 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ class Factory
public static function fromConfig(): Shopify
{
return new Shopify(
config('shopify.credentials.api_key'),
config('shopify.credentials.password'),
config('shopify.credentials.api_access_token'),
config('shopify.credentials.domain'),
config('shopify.credentials.api_version'),
);
Expand All @@ -17,8 +16,7 @@ public static function fromConfig(): Shopify
public static function fromArray(array $data): Shopify
{
return new Shopify(
$data['api_key'],
$data['password'],
$data['api_access_token'],
$data['domain'],
$data['api_version']
);
Expand Down
13 changes: 6 additions & 7 deletions src/Shopify.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class Shopify

protected ?PendingRequest $httpClient = null;

public function __construct(string $apiKey, string $password, string $domain, string $apiVersion)
public function __construct(string $accessToken, string $domain, string $apiVersion)
{
$this->withCredentials($apiKey, $password, $domain, $apiVersion);
$this->withCredentials($accessToken, $domain, $apiVersion);
}

public function cursor(Collection $results): Cursor
Expand All @@ -70,13 +70,13 @@ public function cursor(Collection $results): Cursor
public function getHttpClient(): PendingRequest
{
return $this->httpClient ??= Http::baseUrl($this->getBaseUrl())
->withBasicAuth($this->apiKey, $this->password);
->withHeaders(['X-Shopify-Access-Token' => $this->accessToken]);
}

public function graphQl(): PendingRequest
{
return Http::baseUrl("https://{$this->domain}/admin/api/graphql.json")
->withHeaders(['X-Shopify-Access-Token' => $this->password]);
->withHeaders(['X-Shopify-Access-Token' => $this->accessToken]);
}

public function getBaseUrl(): string
Expand All @@ -91,10 +91,9 @@ public function tap(callable $callback): self
return $this;
}

public function withCredentials(string $apiKey, string $password, string $domain, string $apiVersion): self
public function withCredentials(string $accessToken, string $domain, string $apiVersion): self
{
$this->apiKey = $apiKey;
$this->password = $password;
$this->accessToken = $accessToken;
$this->domain = $domain;
$this->apiVersion = $apiVersion;

Expand Down

0 comments on commit 6ed040f

Please sign in to comment.