Skip to content

Instantly share code, notes, and snippets.

@iamricks
Created January 11, 2022 15:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamricks/3b05489c4d184a719e37ba29a344a53c to your computer and use it in GitHub Desktop.
Save iamricks/3b05489c4d184a719e37ba29a344a53c to your computer and use it in GitHub Desktop.
Overide some class methods and attributes on amz-sp-api gem to allow for grantless operations
AmzSpApi::SpApiClient.class_eval do
def request_lwa_access_token
newself = self.dup
newself.config = config.dup
newself.config.host = 'api.amazon.com'
data, status_code, headers = newself.super_call_api(:POST, '/auth/o2/token',
:header_params => {
'Content-Type' => 'application/x-www-form-urlencoded'
},
:form_params => {
grant_type: config.grant_type || 'refresh_token',
refresh_token: config.refresh_token,
scope: config.scope,
client_id: config.client_id,
client_secret: config.client_secret
},
:return_type => 'Object')
unless data && data[:access_token]
fail ApiError.new(:code => status_code,
:response_headers => headers,
:response_body => data)
end
data
end
end
AmzSpApi::SpConfiguration.class_eval do
attr_accessor :scope
attr_accessor :grant_type
end
@s-dz
Copy link

s-dz commented Jun 18, 2023

Perfect, I tried this and success to request with grantless APIs. I hope that AmzSpApi merges this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment