Skip to content

Commit dd6dc9d

Browse files
committed
Use ShopifyAPI::Clients::HttpClient instead of HTTParty directly in OAuth.validate_auth_callback
1 parent 82e4caf commit dd6dc9d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
44

55
## Unreleased
66
- [#1237](https://github.com/Shopify/shopify-api-ruby/pull/1237) Skip mandatory webhook topic registration/unregistrations
7+
- []() Update `OAuth.validate_auth_callback` to use `ShopifyApi::Clients::HttpClient`.
78

89
## 13.2.0
910

lib/shopify_api/auth/oauth.rb

+15-5
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,25 @@ def validate_auth_callback(cookies:, auth_query:)
7070
raise Errors::InvalidOauthError,
7171
"Invalid state in OAuth callback." unless state == auth_query.state
7272

73-
# TODO: replace this call with the HTTP client once it is built
73+
null_session = Auth::Session.new(shop: auth_query.shop)
7474
body = { client_id: Context.api_key, client_secret: Context.api_secret_key, code: auth_query.code }
75-
response = HTTParty.post("https://#{auth_query.shop}/admin/oauth/access_token", body: body)
76-
unless response.ok?
75+
76+
client = Clients::HttpClient.new(session: null_session, base_path: "/admin/oauth")
77+
response = begin
78+
client.request(
79+
Clients::HttpRequest.new(
80+
http_method: :post,
81+
path: "access_token",
82+
body: body,
83+
body_type: "application/json",
84+
),
85+
)
86+
rescue ShopifyAPI::Errors::HttpResponseError => e
7787
raise Errors::RequestAccessTokenError,
78-
"Cannot complete OAuth process. Received a #{response.code} error while requesting access token."
88+
"Cannot complete OAuth process. Received a #{e.code} error while requesting access token."
7989
end
80-
session_params = response.to_h
8190

91+
session_params = T.cast(response.body, T::Hash[String, T.untyped]).to_h
8292
session = create_new_session(session_params, auth_query.shop)
8393

8494
cookie = if Context.embedded?

0 commit comments

Comments
 (0)