UNPKG

@eclipse-ditto/ditto-javascript-client-node

Version:

Node.js(r) implementation of Eclipse Ditto JavaScript API.

60 lines 1.86 kB
"use strict"; /*! * Copyright (c) 2020 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0 * * SPDX-License-Identifier: EPL-2.0 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DefaultTokenSupplier = exports.HttpBearerAuth = exports.BearerAuth = void 0; /** * Provides OAuth-Style authentication via bearer tokens */ class BearerAuth { /** * Build a new instance of bearer auth * @param tokenSupplier Implementation of the TokenSupplier class to provide tokens for authentication */ constructor(tokenSupplier) { this.supplier = tokenSupplier; } } exports.BearerAuth = BearerAuth; /** * Http implementation of bearer auth using the Authorization HTTP header. */ class HttpBearerAuth extends BearerAuth { /** * Creates a new instance for HTTP connections * @param supplier TokenSupplier used to get a token */ static newInstance(supplier) { return new HttpBearerAuth(supplier); } authenticateWithUrl(originalUrl) { return originalUrl; } authenticateWithHeaders(originalHeaders) { return originalHeaders.set('Authorization', `Bearer ${this.supplier.getToken()}`); } } exports.HttpBearerAuth = HttpBearerAuth; /** * Static implementation of the TokenSupplier interface that always returns the same token */ class DefaultTokenSupplier { constructor(token) { this.token = token; } getToken() { return this.token; } } exports.DefaultTokenSupplier = DefaultTokenSupplier; //# sourceMappingURL=bearer-auth.js.map