Skip to content

Commit 6ed040f

Browse files
committed
feat: use access_token instead of basic auth and update config to reflect this
1 parent 82df528 commit 6ed040f

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

config/shopify.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55
'credentials' => [
66

77
/*
8-
* The API key from private app credentials.
8+
* The API access token from the private app.
99
*/
10-
'api_key' => env('SHOPIFY_API_KEY', ''),
11-
12-
/*
13-
* The password from private app credentials.
14-
*/
15-
'password' => env('SHOPIFY_PASSWORD', ''),
10+
'api_access_token' => env('SHOPIFY_API_ACCESS_TOKEN', ''),
1611

1712
/*
1813
* The shopify domain for your shop.

src/Factory.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ class Factory
77
public static function fromConfig(): Shopify
88
{
99
return new Shopify(
10-
config('shopify.credentials.api_key'),
11-
config('shopify.credentials.password'),
10+
config('shopify.credentials.api_access_token'),
1211
config('shopify.credentials.domain'),
1312
config('shopify.credentials.api_version'),
1413
);
@@ -17,8 +16,7 @@ public static function fromConfig(): Shopify
1716
public static function fromArray(array $data): Shopify
1817
{
1918
return new Shopify(
20-
$data['api_key'],
21-
$data['password'],
19+
$data['api_access_token'],
2220
$data['domain'],
2321
$data['api_version']
2422
);

src/Shopify.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class Shopify
5757

5858
protected ?PendingRequest $httpClient = null;
5959

60-
public function __construct(string $apiKey, string $password, string $domain, string $apiVersion)
60+
public function __construct(string $accessToken, string $domain, string $apiVersion)
6161
{
62-
$this->withCredentials($apiKey, $password, $domain, $apiVersion);
62+
$this->withCredentials($accessToken, $domain, $apiVersion);
6363
}
6464

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

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

8282
public function getBaseUrl(): string
@@ -91,10 +91,9 @@ public function tap(callable $callback): self
9191
return $this;
9292
}
9393

94-
public function withCredentials(string $apiKey, string $password, string $domain, string $apiVersion): self
94+
public function withCredentials(string $accessToken, string $domain, string $apiVersion): self
9595
{
96-
$this->apiKey = $apiKey;
97-
$this->password = $password;
96+
$this->accessToken = $accessToken;
9897
$this->domain = $domain;
9998
$this->apiVersion = $apiVersion;
10099

0 commit comments

Comments
 (0)