@dasch-swiss/dsp-js
Version:
JavaScript library that handles API requests to Knora
78 lines • 3.54 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { catchError, map } from "rxjs";
import { ApiResponseData } from "../../../models/api-response-data";
import { CredentialsResponse } from "../../../models/v2/authentication/credentials-response";
import { LoginResponse } from "../../../models/v2/authentication/login-response";
import { LogoutResponse } from "../../../models/v2/authentication/logout-response";
import { Endpoint } from "../../endpoint";
/**
* Handles requests to the authentication route of the Knora API.
*
* @category Endpoint V2
*/
var AuthenticationEndpointV2 = /** @class */ (function (_super) {
__extends(AuthenticationEndpointV2, _super);
function AuthenticationEndpointV2() {
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.
*/
AuthenticationEndpointV2.prototype.login = function (property, id, password) {
var _this = this;
var credentials = {
password: password
};
credentials[property] = id;
return this.httpPost("", credentials).pipe(map(function (ajaxResponse) {
// Make sure the web token is stored.
var responseData = ApiResponseData.fromAjaxResponse(ajaxResponse, LoginResponse, _this.jsonConvert);
_this.jsonWebToken = responseData.body.token;
return responseData;
}), catchError(function (error) { return _this.handleError(error); }));
};
/**
* Logs out the user and destroys the session on the server- and client-side.
*/
AuthenticationEndpointV2.prototype.logout = function () {
var _this = this;
return this.httpDelete("").pipe(map(function (ajaxResponse) {
// Make sure the web token is removed.
var responseData = ApiResponseData.fromAjaxResponse(ajaxResponse, LogoutResponse, _this.jsonConvert);
_this.jsonWebToken = "";
return responseData;
}), catchError(function (error) { return _this.handleError(error); }));
};
/**
* Checks credentials.
*
* Returns a `ApiResponseError` if the client is not authorized.
*/
AuthenticationEndpointV2.prototype.checkCredentials = function () {
var _this = this;
return this.httpGet("").pipe(map(function (ajaxResponse) {
return ApiResponseData.fromAjaxResponse(ajaxResponse, CredentialsResponse);
}), catchError(function (error) { return _this.handleError(error); }));
};
return AuthenticationEndpointV2;
}(Endpoint));
export { AuthenticationEndpointV2 };
//# sourceMappingURL=authentication-endpoint-v2.js.map