@pubby/sdk
Version:
Pubby Development Kit
57 lines (52 loc) • 2.17 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var tslib = require('tslib');
var oauth = require('./oauth.js');
var BotStrategy = /** @class */ (function () {
function BotStrategy(options) {
this.options = options;
}
BotStrategy.prototype.init = function (pubby) {
return tslib.__awaiter(this, void 0, void 0, function () {
var _a;
return tslib.__generator(this, function (_b) {
switch (_b.label) {
case 0:
this.oauth = new oauth.OAuthClient({
tokenUrl: pubby.config.current.baseURL + "/oauth/token",
clientId: this.options.clientId,
clientSecret: this.options.secret,
});
return [4 /*yield*/, this.oauth.requestTokenAndSave(oauth.ClientCredentialsGrant(["user"]))];
case 1:
_b.sent();
_a = this;
return [4 /*yield*/, pubby.api.user.getProfile()];
case 2:
_a.user = _b.sent();
if (!pubby.has("ws")) return [3 /*break*/, 4];
return [4 /*yield*/, pubby.ws.connect()];
case 3:
_b.sent();
_b.label = 4;
case 4: return [2 /*return*/];
}
});
});
};
BotStrategy.prototype.getToken = function () {
return this.oauth.getToken().then(function (token) { return token.accessToken; });
};
BotStrategy.prototype.getTicket = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
return tslib.__generator(this, function (_a) {
return [2 /*return*/, this.getToken()];
});
});
};
BotStrategy.prototype.isAuthenticated = function () {
return this.oauth.isAuthenticated();
};
return BotStrategy;
}());
exports.BotStrategy = BotStrategy;