UNPKG

@eclipse-ditto/ditto-javascript-client-dom

Version:

DOM implementation of Eclipse Ditto JavaScript API to be used in browsers.

54 lines 1.59 kB
/*! * 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 */ /** * Provides OAuth-Style authentication via bearer tokens */ export 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; } } /** * Http implementation of bearer auth using the Authorization HTTP header. */ export 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()}`); } } /** * Static implementation of the TokenSupplier interface that always returns the same token */ export class DefaultTokenSupplier { constructor(token) { this.token = token; } getToken() { return this.token; } } //# sourceMappingURL=bearer-auth.js.map