shopify_api-graphql-request 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 472bded2f6c1de2498e9e8862034a07a509ca931d6cba183e2eb10e0dba38b0e
4
- data.tar.gz: a123ea8eb1512e9a0c8ac90d469296a78e88d10761769eb5461d5499bcac3eda
3
+ metadata.gz: e53b915f0365c0b28cc149ef491d1b3ebaf777501d56b4c0335521dc529bc068
4
+ data.tar.gz: 01d0bf40075fdb03d5ee2db1434184975969c5b1ea3b0cd44ab46c4095b465fa
5
5
  SHA512:
6
- metadata.gz: 8bdd31a98f8841b07532adc0e9bbf88089ac09912addf266c2092381e6ea1a08fd00462a554392593c71f4ac8be1c09c2134e05c4fccb6736f6f0dc0cf3c5e6c
7
- data.tar.gz: e17c81fc3d2d32ce31b6f5eab2c78e7e8871ec5214d2715de8ba8dfed15f6213b3d251f6e7297cc6a797bcce06195ee4d98497839eb845f2f339d975a72b8e8f
6
+ metadata.gz: 0fb059eb97bbc32509727fd820948112266bdf1d03573b5b383338804ae33228de51cfbfd7b6bfa9552a419863c4e7b210fed97c44660a9ae2a65e3f955869d9
7
+ data.tar.gz: 3c0da8d8c92939074b87b2e15e503d2750de88884085ef75bf18c39f45c63df4207d11ab4226bf4c7be3e52ea613ae4c464d9a5e16e89940710505b0bf180cc9
data/Changes CHANGED
@@ -1,3 +1,7 @@
1
+ v0.2.2 2026-11-29
2
+ --------------------
3
+ Add AccessToken::Error to expose underlying OAuth error
4
+
1
5
  v0.2.1 2026-11-18
2
6
  --------------------
3
7
  Remove warn output on HTTP error
data/README.md CHANGED
@@ -429,6 +429,17 @@ The task reads the PEM file (private or public key) given by `KEY` and outputs a
429
429
  rake shopify_api:graphql:request:jwk_export KID=your-key-id ALG=RS256 KEY=private_key.pem
430
430
  ```
431
431
 
432
+ ### Generating an Application-Only Access Token
433
+
434
+ This requires the [JWK key](#exporting-your-public-key-as-a-json-web-key-jwk) to have been uploaded to your app's configuration in the Shopify Developer Dashboards.
435
+ One this has been done you can generate an [offline application-only access token](#expiring-offline-application-only-access-tokens) using a client assertion:
436
+
437
+ ```sh
438
+ rake shopify_api:graphql:request:generate_app_only_token SHOPIFY_API_KEY=your-client-id KEY=private_key.pem KID=your-key-id SHOP=my-shop
439
+ ```
440
+
441
+ The `SHOPIFY_API_KEY`, `KEY` (path to the private key PEM file), `KID`, and `SHOP` arguments are all required. The token response is printed as pretty-printed JSON.
442
+
432
443
  ### More Info
433
444
 
434
445
  For more information checkout [the API docs](https://rdoc.info/gems/shopify_api-graphql-request)
@@ -16,6 +16,15 @@ module ShopifyAPI
16
16
  # Shopify OAuth access token operations
17
17
  #
18
18
  class AccessToken
19
+ class Error < ShopifyAPI::GraphQL::Request::Error
20
+ attr_reader :error
21
+
22
+ def initialize(message = nil, error = nil)
23
+ super(message)
24
+ @error = error
25
+ end
26
+ end
27
+
19
28
  InvalidTokenError = Class.new(Error)
20
29
  InvalidRefreshTokenError = Class.new(Error)
21
30
 
@@ -209,13 +218,13 @@ module ShopifyAPI
209
218
  message = error_message(body)
210
219
 
211
220
  if response.code == "400" && (error == "invalid_subject_token" || error == "invalid_requested_token_type")
212
- raise InvalidTokenError, "failed to migrate access token for #{domain}: #{message}"
221
+ raise InvalidTokenError.new("failed to migrate access token for #{domain}: #{message}", error)
213
222
  # RFC 6749 §5.2 specifies HTTP 400 for invalid_grant, but Shopify returns HTTP 401
214
223
  # when a refresh token is inactive, expired, or already rotated. Check both to be safe.
215
224
  elsif (response.code == "400" || response.code == "401") && error == "invalid_grant"
216
- raise InvalidRefreshTokenError, "failed to refresh access token for #{domain}: #{message}"
225
+ raise InvalidRefreshTokenError.new("failed to refresh access token for #{domain}: #{message}", error)
217
226
  else
218
- raise Error, "failed to request access token for #{domain}: #{message} (HTTP #{response.code})"
227
+ raise Error.new("failed to request access token for #{domain}: #{message} (HTTP #{response.code})", error)
219
228
  end
220
229
  end
221
230
 
@@ -3,7 +3,7 @@
3
3
  module ShopifyAPI
4
4
  module GraphQL
5
5
  class Request
6
- VERSION = "0.2.1"
6
+ VERSION = "0.2.2"
7
7
  end
8
8
  end
9
9
  end
@@ -5,6 +5,8 @@ require "jwt"
5
5
  require "openssl"
6
6
 
7
7
  require "shopify_api/graphql/request"
8
+ require "shopify_api/graphql/request/shop"
9
+ require "shopify_api/graphql/request/oauth/access_token"
8
10
  require "shopify_api/graphql/request/oauth/access_token_migrator"
9
11
  require "shopify_api/graphql/request/oauth/client_assertion"
10
12
 
@@ -78,6 +80,32 @@ namespace :shopify_api do
78
80
  # Only the public parameters are exported
79
81
  puts JSON.pretty_generate(JWT::JWK.new(key, :kid => kid, :alg => alg, :use => "sig").export)
80
82
  end
83
+
84
+ desc "Generate an application-only access token using a client assertion. Requires SHOPIFY_API_KEY, KEY (PEM file), KID, and SHOP."
85
+ task :generate_app_only_token do
86
+ client_id = ENV["SHOPIFY_API_KEY"].to_s.strip
87
+ path = ENV["KEY"].to_s.strip
88
+ kid = ENV["KID"].to_s.strip
89
+ shop = ENV["SHOP"].to_s.strip
90
+
91
+ abort "SHOPIFY_API_KEY required" if client_id.empty?
92
+ abort "KEY required" if path.empty?
93
+ abort "KID required" if kid.empty?
94
+ abort "SHOP required" if shop.empty?
95
+
96
+ abort "KEY file not found: #{path}" unless File.file?(path)
97
+
98
+ begin
99
+ shop = ShopifyAPI::GraphQL::Request::Shop.new(shop)
100
+ assertion = ShopifyAPI::GraphQL::Request::OAuth::ClientAssertion.new(client_id, File.read(path), kid)
101
+ client = ShopifyAPI::GraphQL::Request::OAuth::AccessToken.new(client_id)
102
+ result = client.client_credentials(shop, assertion)
103
+ rescue ArgumentError, ShopifyAPI::GraphQL::Request::Error => e
104
+ abort e.message
105
+ end
106
+
107
+ puts JSON.pretty_generate(result)
108
+ end
81
109
  end
82
110
  end
83
111
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_api-graphql-request
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skye Shaw
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-18 00:00:00.000000000 Z
11
+ date: 2026-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shopify_api-graphql-tiny