restpki-client
Version:
Classes to consume Lacuna Software REST PKI
63 lines (53 loc) • 1.41 kB
JavaScript
;
const {AuthenticationResult} = require('./authentication-result');
const { CompleteAuth } = require('./complete-auth');
class Authentication {
constructor(client) {
this._client = client;
}
async startWithWebPki(securityContextId) {
let request = {
securityContextId: securityContextId
};
try {
let response = await this._client.getRestClient().post('Api/Authentications', request);
return response.token;
} catch (err) {
throw err;
}
}
async start(securityContextId) {
let request = {
securityContextId: securityContextId
};
try {
let response = await this._client.getRestClient().post('Api/Authentications', request);
return response;
} catch (err) {
throw err;
}
}
async completeWithWebPki(token) {
try {
let response = await this._client.getRestClient().post(`Api/Authentications/${token}/Finalize`);
return new AuthenticationResult(response);
} catch (err) {
throw err;
}
}
/**
*
* @param {string} token
* @param {CompleteAuth} request
* @returns
*/
async complete(token, request) {
try {
let response = await this._client.getRestClient().post(`Api/Authentications/${token}/SignedBytes`, request);
return new AuthenticationResult(response);
} catch (err) {
throw err;
}
}
}
exports.Authentication = Authentication;