Auth keybase and clearbit

Summary:
Fix to pass N1 ID auth through to edgehill-server for remaining services
(clearbit and keybase) that request authing against the Nylas API. We need
to pass along the N1 ID.

This also requires an Edgehill Server patch here:
https://phab.nylas.com/D3149

Test Plan: Manual.

Reviewers: bengotow, juan

Differential Revision: https://phab.nylas.com/D3151
This commit is contained in:
Evan Morikawa 2016-08-02 16:15:45 -07:00
parent b46f60fc1c
commit 0de68632df
3 changed files with 25 additions and 13 deletions

View file

@ -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:

View file

@ -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)

View file

@ -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();
}
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();