@mindconnect/mindconnect-nodejs
Version:
NodeJS Library for Siemens Insights Hub Connectivity - TypeScript SDK for Insights Hub and Industrial IoT - Command Line Interface - Insights Hub Development Proxy (Siemens Insights Hub was formerly known as MindSphere)
96 lines • 3.23 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserAuth = void 0;
const mindconnect_base_1 = require("./mindconnect-base");
const utils_1 = require("./utils");
/**
* User Authenticator for Backend Authentication in NodeJS
*
* @see https://developer.mindsphere.io/concepts/concept-authentication.html#calling-apis-from-backend
*
* @export
* @class UserAuth
* @extends {MindConnectBase}
* @implements {TokenRotation}
*/
class UserAuth extends mindconnect_base_1.MindConnectBase {
/**
* Creates an instance of UserAuth.
* extract token from http request headers (req.get("authorization"))
*
* @param {string} token
* @param {string} gateway
*
* extract token from curreny http request:
* Gateway has to follow the https://gateway.{region}.{mindsphere-domain} schema
*
* @see https://developer.mindsphere.io/concepts/concept-authentication.html#calling-apis-from-backend
*
* @memberOf UserAuth
*/
constructor(token, gateway) {
super();
if (!(0, utils_1.isUrl)(gateway)) {
throw new Error("the gateway must be an URL (e.g. https://gateway.eu1.mindsphere.io");
}
this._token = token.replace("Bearer", "").trim(); // just for the case that people pass complete bearer token with leading bearer
this._gateway = gateway;
}
/**
/**
* * Returns true; MindSphere Gateway is taking care of this
*
* @returns {Promise<boolean>}
*
* @memberOf BrowserAuth
*/
RenewToken() {
return __awaiter(this, void 0, void 0, function* () {
return true; // the mindsphere gateway is doing this for us
});
}
/**
* * Returns ""; MindSphere Gateway is taking care of this
*
* @returns {Promise<string>}
*
* @memberOf BrowserAuth
*/
GetToken() {
return __awaiter(this, void 0, void 0, function* () {
return this._token; // the mindsphere gateway is doing this for us
});
}
/**
* returns the configured gateway
*
* @returns {string}
*
* @memberOf BrowserAuth
*/
GetGateway() {
return this._gateway;
}
/**
*
* * Returns ""; MindSphere Gateway is taking care of this
*
* @returns {string}
*
* @memberOf BrowserAuth
*/
GetTenant() {
return ""; // the mindsphere gateway is doing this for us
}
}
exports.UserAuth = UserAuth;
//# sourceMappingURL=user-auth.js.map