Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/muffin_man/api_account_credential/credential_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module MuffinMan::ApiAccountCredential
Copy link
Contributor

@sanjjaymahalingam sanjjaymahalingam Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should just be like how the other APIs have been implemented where a sp api client can be created for Application Management API v2023-11-30.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm can we have something like this MuffinMan::Credential::V20231130 ?

class CredentialHelper
NEW_APP_CREDENTIAL_URL = "https://sellingpartnerapi-na.amazon.com/applications/2023-11-30/clientSecret".freeze

def self.create_new_credentials(access_token)
response = Typhoeus.post(
NEW_APP_CREDENTIAL_URL,
headers: {
"x-amz-access-token" => "#{access_token}"
}
)
if response.code != 204
error_body = JSON.parse(response.body)
error = "#{error_body['error']}: #{error_body['error_description']} "
raise MuffinMan::Error, error
end
response.code
end
end
end
22 changes: 22 additions & 0 deletions lib/muffin_man/lwa/auth_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,27 @@ def self.get_refresh_token(client_id, client_secret, auth_code)
end
JSON.parse(response.body)["refresh_token"]
end

def self.get_client_credential_refresh_token(client_id, client_secret)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitinbhakar @sanjjaymahalingam I am not sure about this can you check once, in muffin man sp_api_client.rb we have method called retrieve_lwa_access_token will that be useful to generate the refresh_token? and then use for client creation?

Copy link
Contributor Author

@nitinbhakar nitinbhakar Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rohit-lingayat-sd Yes that can be useful but thats a private method so can't call it directly.
So should i use send() to call private method?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm no, then we can go with your approach then

body = {
grant_type: "client_credentials",
client_id: client_id,
client_secret: client_secret
}

response = Typhoeus.post(
ACCESS_TOKEN_URL,
body: URI.encode_www_form(body),
headers: {
"Content-Type" => "application/x-www-form-urlencoded;charset=UTF-8"
}
)
if response.code != 200
error_body = JSON.parse(response.body)
error = "#{error_body["error"]}: #{error_body["error_description"]}"
raise MuffinMan::Error, error
end
JSON.parse(response.body)["refresh_token"]
end
end
end
Loading