OfficeDev / office-js-helpers

[ARCHIVED] A collection of helpers to simplify development of Office Add-ins & Microsoft Teams Tabs
MIT License
126 stars 56 forks source link

Recursive call calling out of stack #102

Open sremiger1 opened 6 years ago

sremiger1 commented 6 years ago
TokenStorage.prototype.get = function (provider) {
        var token = _super.prototype.get.call(this, provider);
        if (token == null) {
            return token;
        }
        var expired = TokenStorage.hasExpired(token);
        if (expired) {
            _super.prototype.delete.call(this, provider);
            return null;
        } else {
            return token;
        }
    };

_super.prototype.delete.call(this, provider); is being called if expired. Which in turn is calling get causing a circular reference and blowing the stack.

Storage.prototype.delete = function (key) {
        try {
            var value = this.get(key);
            if (value === undefined) {
                throw new ReferenceError("Key: " + key + " not found.");
            }
            var scopedKey = this._scope(key);
            this._storage.removeItem(scopedKey);
            return value;
        } catch (error) {
            throw new __WEBPACK_IMPORTED_MODULE_5__errors_exception__["a" /* Exception */]("Unable to delete '" + key + "' from storage", error);
        }
    };
sremiger1 commented 6 years ago

Adding more details to the issue.

When getting an existing token that is expired it will attempt to delete said token and call get again which causes the circular reference

To fix simply rename token.manager.ts get(provider: string): IToken {

to

token.manager.ts getValidToken(provider: string): IToken {

The get call within the delete then will call the proper get.