Created
January 11, 2022 15:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perfect, I tried this and success to request with grantless APIs. I hope that AmzSpApi merges this.