Closed TotallyNotChase closed 4 years ago
@pajaydev did you get a chance at reviewing the changes?
@TotallyNotChase Sorry for the delay, I was caught up with some other work. I gave a small comment, kindly let me know if you are busy I will merge this and do it as part of cleanup. Thanks again for your patience 👍
@pajaydev The changes are now migrated to src/credentials.js
@pajaydev sounds good! thanks!
How to properly use that feature? Please post the working code to get an user access token by a refresh token. The demo code can't work because the refresh token parameter of the getUserTokenByRefresh method is missing.
Goal of the pull request:
Description
Sets up oauth for both application access tokens (client credentials) and user access tokens (authorization grant). Closes #93
Changelog
getUserAuthorizationUrl
,getUserTokenByCode
, andgetUserTokenByRefresh
for getting user access tokenssetUserAccessToken
andsetAppAccessToken
, for setting user token and app access token respectively. These are designed to take the ebay api response as a parameter and set them accordinglyoauthEndpoint
for bothSANDBOX
andPROD
to constants, this is used for generating the user consent urlsrc/common-utils/index/getAccessToken
->src/index/getAccessToken
, with a few minor changes. Namely, explicitly setthis.options.data
instead of usingthis.options.body
. This is done to be streamlined across all the token getter functions.getUserTokenByCode
must use a customthis.options.data
as it requires acode
.Note: This kind of makes
this.options.body.grant_type
useless, because each grant type has its own function but this will not break front end user functionality. In time, I suggest theoptions.body
be completely removed and thescopes
be passed in to their respective token getters as a parameter, hence achieving Single Responsibility Principle.src/common-utils/index/setAccessToken
->src/index/setAppAccessToken
, with a few minor changes. The parameter is now the full response returned by the ebay server and instead of being stored inoptions.access_token
, it's now stored inoptions.appAccessToken
this.options.access_token
->this.options.appAccessToken
getUserToken
demoThings to keep in mind during dev
this.options.appAccessToken
(previouslythis.options.access_token
)this.options.userAccessToken
(previously unavailable)this.options.refreshToken
getUserAuthorizationUrl
, the code present in the redirected url is url encoded. It must be url decoded before being passed intogetUserTokenByCode