diff --git a/internal_packages/keybase/lib/keybase-search.cjsx b/internal_packages/keybase/lib/keybase-search.cjsx index 964c981de..1836d8071 100755 --- a/internal_packages/keybase/lib/keybase-search.cjsx +++ b/internal_packages/keybase/lib/keybase-search.cjsx @@ -24,15 +24,12 @@ class KeybaseInviteButton extends React.Component _onGetKeybaseInvite: => @setState({loading: true}) - token = AccountStore.tokenForAccountId(AccountStore.accounts()[0].id) errorHandler = (err) => @setState({loading: false}) NylasEnv.showErrorDialog(err.message) EdgehillAPI.makeRequest - auth: - user: token - pass: "" + authWithNylasAPI: true path: "/keybase-invite", method: "POST", body: diff --git a/internal_packages/participant-profile/lib/clearbit-data-source.coffee b/internal_packages/participant-profile/lib/clearbit-data-source.coffee index ac2252647..95cc2b00d 100644 --- a/internal_packages/participant-profile/lib/clearbit-data-source.coffee +++ b/internal_packages/participant-profile/lib/clearbit-data-source.coffee @@ -10,12 +10,9 @@ module.exports = class ClearbitDataSource find: ({email, tryCount}) -> if (tryCount ? 0) >= MAX_RETRY return Promise.resolve(null) - tok = AccountStore.tokenForAccountId(AccountStore.accounts()[0].id) new Promise (resolve, reject) => EdgehillAPI.makeRequest - auth: - user: tok - pass: "" + authWithNylasAPI: true path: "/proxy/clearbit/#{@clearbitAPI()}/find?email=#{email}", success: (body, response) => @parseResponse(body, response, email, tryCount).then(resolve).catch(reject) diff --git a/src/flux/edgehill-api.es6 b/src/flux/edgehill-api.es6 index f98359a7d..77131ebec 100644 --- a/src/flux/edgehill-api.es6 +++ b/src/flux/edgehill-api.es6 @@ -1,3 +1,4 @@ +import AccountStore from './stores/account-store' import NylasAPIRequest from './nylas-api-request'; class EdgehillAPI { @@ -19,16 +20,33 @@ class EdgehillAPI { } } + accessTokenForAccountId(aid) { + return AccountStore.tokenForAccountId(aid) + } + makeRequest(options = {}) { if (NylasEnv.getLoadSettings().isSpec) { return Promise.resolve(); } - options.auth = options.auth || { - user: '', - pass: '', - sendImmediately: true, - }; + if (options.authWithNylasAPI) { + // The account doesn't matter for Edgehill server. We just need to + // ensure it's a valid account. + options.accountId = AccountStore.accounts()[0].id; + // The `NylasAPIRequest` object will grab the appropriate tokens. + delete options.auth; + delete options.authWithNylasAPI; + } else { + // A majority of Edgehill-server (aka auth) requests neither need + // (nor have) account or N1 ID tokens to provide. + // The existence of the options.auth object will prevent + // `NylasAPIRequest` from constructing them from existing tokens + options.auth = options.auth || { + user: '', + pass: '', + sendImmediately: true, + }; + } const req = new NylasAPIRequest(this, options); return req.run();