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

AbstractToken.js « Token « Authorization « src - git.mdns.eu/nextcloud/passwords-client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cb7e5e61e0f4b64c87eb6abcb3d80acc5a321a1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
        };
    }
}