diff --git a/appstore.js b/appstore.js index be6402a..96245a4 100644 --- a/appstore.js +++ b/appstore.js @@ -24,7 +24,7 @@ function AppStore(origin) { } AppStore.prototype.getAccessToken = function (user) { - var res = request.get(this._origin + '/api/v1/login').auth(user.email, user.password).end(); + var res = request.post(this._origin + '/api/v1/login').send({ email: user.email, password: user.password, persistent: true }).end(); common.verifyResponse2xx(res, 'Could not login as user:' + user.email + ' password:' + user.password); return res.body.accessToken; }; diff --git a/cloudron.js b/cloudron.js index 5888345..9b94e93 100644 --- a/cloudron.js +++ b/cloudron.js @@ -799,11 +799,8 @@ Cloudron.prototype.checkNginxRateLimit = function (owner, times, callback) { }); }; -Cloudron.prototype.setAppstoreConfig = function (email, password, callback) { - superagent.post(process.env.APPSTORE_API_ORIGIN + '/api/v1/login').send({ email: email, password: password, persistent: true }).end(function (error, result) { - if (error || result.statusCode !== 200) return callback('Error logging into appstore:' + error.message); - - superagent.post('https://' + that._adminFqdn + '/api/v1/settings/appstore_config').send({ userId: result.userId, token: result.accessToken }).end(callback); - }); +Cloudron.prototype.setAppstoreConfig = function (id, token, callback) { + var res = request.post('https://' + that._adminFqdn + '/api/v1/settings/appstore_config').send({ userId: id, token: token }).end(); + common.verifyResponse2xx(res, 'Could not set appstore config'); }; diff --git a/test/selfhost-digitalocean-filesystem-test.js b/test/selfhost-digitalocean-filesystem-test.js index 1c4f19c..07b69cc 100644 --- a/test/selfhost-digitalocean-filesystem-test.js +++ b/test/selfhost-digitalocean-filesystem-test.js @@ -239,7 +239,11 @@ describe('Selfhost DigitalOcean with filesystem backend', function () { }); it('can set appstore config', function (done) { - cloudron.setAppstoreConfig(process.env.APPSTORE_USERNAME, process.env.APPSTORE_PASSWORD, done); + var token = appStore.getAccessToken(owner); + appStore.setCredentials(owner.password, token); + var profile = appStore.getProfile(); + console.dir(profile); + cloudron.setAppstoreConfig(profile.id, token); }); it('can update the box', function () {