Add appstore accessToken to subscription setup links

This commit is contained in:
Johannes Zellner
2020-02-21 12:34:40 +01:00
parent af8bb1f0e8
commit 81fb4ab435
5 changed files with 32 additions and 43 deletions

View File

@@ -2207,6 +2207,30 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
});
};
Client.prototype.getAppstoreUserToken = function (callback) {
post('/api/v1/appstore/user_token', {}, null, function (error, data, status) {
if (error) return callback(error);
if (status !== 201) return callback(new ClientError(status, data));
callback(null, data.accessToken);
});
};
// This will change the location
Client.prototype.openSubscriptionSetup = function (subscription) {
var that = this;
this.getAppstoreUserToken(function (error, result) {
if (error) return console.error('Unable to get appstore user token.', error);
var token = result;
var email = subscription.emailEncoded;
var cloudronId = subscription.cloudronId;
window.location.href = that.getConfig().webServerOrigin + '/console.html#/userprofile?view=subscriptions&email=' + email + '&cloudronId=' + cloudronId + '&token=' + token;
});
};
Client.prototype.getAppstoreAppByIdAndVersion = function (appId, version, callback) {
var url = '/api/v1/appstore/apps/' + appId;
if (version && version !== 'latest') url += '/versions/' + version;