import 'expose-loader?AuthenticationContext!../../../../adal-angular/lib/adal.js';
export function createBrowserAuthWrapper(adalConfig) {
    var config = {
        tenant: adalConfig.tenantId,
        clientId: adalConfig.spaClientId,
        postLogoutRedirectUri: window.location.origin,
        endpoints: {
            api: adalConfig.apiId
        },
        cacheLocation: 'localStorage'
    };
    return new BrowserAuthWrapper(new AuthenticationContext(config), adalConfig);
}
var BrowserAuthWrapper = (function () {
    function BrowserAuthWrapper(context, config) {
        this.context = context;
        this.config = config;
    }
    Object.defineProperty(BrowserAuthWrapper.prototype, "token", {
        get: function () {
            return window.localStorage.getItem(this.context.CONSTANTS.STORAGE.IDTOKEN);
        },
        enumerable: true,
        configurable: true
    });
    BrowserAuthWrapper.prototype.handleResponse = function (hash) {
        this.context.handleWindowCallback(hash);
    };
    BrowserAuthWrapper.prototype.acquireTokenInBackground = function () {
        var _this = this;
        var promise = new Promise(function (resolve, reject) {
            // expects user to have been decoded from the id token already. No idea why.
            _this.context.getCachedUser();
            _this.context.acquireToken(_this.config.spaClientId, function (error, token, description) { return (error) ? reject(error) : resolve(token); });
        });
        return promise;
    };
    BrowserAuthWrapper.prototype.login = function () {
        this.context.login();
        return new Promise(function (resolve, reject) { }); // Never resolved, login redirects
    };
    BrowserAuthWrapper.prototype.logout = function () {
        this.context.logOut();
        return new Promise(function (resolve, reject) { }); // Never resolved, logout redirects
    };
    return BrowserAuthWrapper;
}());
//# sourceMappingURL=browser-auth-wrapper.js.map