UNPKG

@itwin/insights-client

Version:

Insights client for the iTwin platform

46 lines 2.47 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import { inject, injectable } from "inversify"; import { TestAuthorizationClient } from "./TestAuthorizationClient"; import { TestAuthorizationProviderConfig } from "./TestAuthorizationProviderConfig"; let TestAuthorizationProvider = class TestAuthorizationProvider { constructor(_config, _testiModelsAuthClient) { this._config = _config; this._testiModelsAuthClient = _testiModelsAuthClient; this._authorizations = {}; } getAdmin1Authorization() { return this.getAuthorization({ ...this._config.testUsers.admin1, scopes: this._config.apiScopes }); } getAuthorization(testUser) { return async () => { const userKey = this.getKey(testUser); if (!this._authorizations[userKey]) { const accessToken = await this._testiModelsAuthClient.getAccessToken(testUser); this._authorizations[userKey] = { scheme: "Bearer", token: accessToken }; } return this._authorizations[userKey]; }; } getKey(testUser) { return `${testUser.email}+${testUser.scopes}`; } }; TestAuthorizationProvider = __decorate([ injectable(), __param(0, inject(TestAuthorizationProviderConfig)), __param(1, inject(TestAuthorizationClient)) ], TestAuthorizationProvider); export { TestAuthorizationProvider }; //# sourceMappingURL=TestAuthorizationProvider.js.map