Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.mdns.eu/nextcloud/passwords-client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/Authorization/Token/AbstractToken.js')
-rw-r--r--src/Authorization/Token/AbstractToken.js101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/Authorization/Token/AbstractToken.js b/src/Authorization/Token/AbstractToken.js
new file mode 100644
index 0000000..cb7e5e6
--- /dev/null
+++ b/src/Authorization/Token/AbstractToken.js
@@ -0,0 +1,101 @@
+export default class AbstractToken {
+
+ /**
+ *
+ * @param {BasicPasswordsClient} api
+ * @param {String} id
+ * @param {String} label
+ * @param {String} description
+ * @param {Boolean} request
+ */
+ constructor(api, id, label, description, request) {
+ this._id = id;
+ this._api = api;
+ this._label = label;
+ this._description = description;
+ this._request = request;
+ this._token = null;
+ }
+
+ /**
+ *
+ * @return {String}
+ */
+ getType() {
+ return 'abstract-token';
+ }
+
+ /**
+ *
+ * @return {String}
+ */
+ getId() {
+ return this._id;
+ }
+
+ /**
+ *
+ * @return {String}
+ */
+ getLabel() {
+ return this._label;
+ }
+
+ /**
+ *
+ * @return {String}
+ */
+ getDescription() {
+ return this._description;
+ }
+
+ /**
+ *
+ * @return {Boolean}
+ */
+ requiresRequest() {
+ return this._request;
+ }
+
+ /**
+ *
+ * @return {(String|null)}
+ */
+ getToken() {
+ return this._token;
+ }
+
+ /**
+ *
+ * @return {Promise<boolean>}
+ */
+ async sendRequest() {
+ if(!this.requiresRequest()) return true;
+
+ try {
+ await this._api
+ .getRequest()
+ .setPath(`1.0/token/${this._id}/request`)
+ .send();
+ return true;
+ } catch(e) {
+ console.error(e);
+ }
+
+ return false;
+ }
+
+ /**
+ *
+ * @return {Object}
+ */
+ toJSON() {
+ return {
+ type : this.getType,
+ id : this._id,
+ label : this._label,
+ description: this._description,
+ request : this._request
+ };
+ }
+} \ No newline at end of file