@knora/api
Version:
JavaScript library that handles API requests to Knora
76 lines • 3.63 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var operators_1 = require("rxjs/operators");
var api_response_data_1 = require("../../../models/api-response-data");
var credentials_response_1 = require("../../../models/v2/authentication/credentials-response");
var login_response_1 = require("../../../models/v2/authentication/login-response");
var logout_response_1 = require("../../../models/v2/authentication/logout-response");
var endpoint_1 = require("../../endpoint");
/**
* Handles requests to the authentication route of the Knora API.
*/
var AuthenticationEndpoint = /** @class */ (function (_super) {
__extends(AuthenticationEndpoint, _super);
function AuthenticationEndpoint() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Logs in a user.
*
* @param property The name of the property by which the user is identified.
* @param id the given user.
* @param password the user's password.
*/
AuthenticationEndpoint.prototype.login = function (property, id, password) {
var _this = this;
var credentials = {
password: password
};
credentials[property] = id;
return this.httpPost("", credentials).pipe(operators_1.map(function (ajaxResponse) {
// Make sure the web token is stored.
var responseData = api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, login_response_1.LoginResponse, _this.jsonConvert);
_this.jsonWebToken = responseData.body.token;
return responseData;
}), operators_1.catchError(function (error) { return _this.handleError(error); }));
};
/**
* Logs out the user and destroys the session on the server- and client-side.
*/
AuthenticationEndpoint.prototype.logout = function () {
var _this = this;
return this.httpDelete("").pipe(operators_1.map(function (ajaxResponse) {
// Make sure the web token is removed.
var responseData = api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, logout_response_1.LogoutResponse, _this.jsonConvert);
_this.jsonWebToken = "";
return responseData;
}), operators_1.catchError(function (error) { return _this.handleError(error); }));
};
/**
* Checks credentials.
*
* Returns a `ApiResponseError` if the client is not authorized.
*/
AuthenticationEndpoint.prototype.checkCredentials = function () {
var _this = this;
return this.httpGet("").pipe(operators_1.map(function (ajaxResponse) {
return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, credentials_response_1.CredentialsResponse);
}), operators_1.catchError(function (error) { return _this.handleError(error); }));
};
return AuthenticationEndpoint;
}(endpoint_1.Endpoint));
exports.AuthenticationEndpoint = AuthenticationEndpoint;
//# sourceMappingURL=authentication-endpoint.js.map