Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/ZcapClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ export class ZcapClient {
* invoked. Default: 'read'.
* @param {object} [options.headers] - The additional headers to sign and
* send along with the HTTP request. Default: {}.
* @param {object} [options.authzHeaderName] - The name of the header in which
* the signature will be placed. Default: 'authorization'.
* @param {object} options.json - The JSON object, if any, to send with the
* request.
*
Expand All @@ -300,6 +302,7 @@ export class ZcapClient {
method = 'get',
action = 'read',
headers = {},
authzHeaderName = 'authorization',
json
} = {}) {
if(!this.invocationSigner) {
Expand Down Expand Up @@ -369,7 +372,8 @@ export class ZcapClient {
json,
invocationSigner,
capability: capability || await generateZcapUri({url}),
capabilityAction: action
capabilityAction: action,
authzHeaderName
});

// build the final request
Expand All @@ -394,16 +398,19 @@ export class ZcapClient {
* send along with the HTTP request.
* @param {string} [options.capability] - The capability to invoke at the
* given URL. Default: generate root capability from options.url.
* @param {object} [options.authzHeaderName] - The name of the header in which
* the signature will be placed. Default: 'authorization'.
*
* @returns {Promise<object>} - A promise that resolves to an HTTP response.
*/
async read({
url,
headers = {},
capability
capability,
authzHeaderName = 'authorization'
} = {}) {
return this.request({
url, capability, method: 'get', action: 'read', headers
url, capability, method: 'get', action: 'read', headers, authzHeaderName
});
}

Expand All @@ -420,17 +427,20 @@ export class ZcapClient {
* send along with the HTTP request.
* @param {string} [options.capability] - The capability to invoke at the
* given URL. Default: generate root capability from options.url.
* @param {object} [options.authzHeaderName] - The name of the header in which
* the signature will be placed. Default: 'authorization'.
*
* @returns {Promise<object>} - A promise that resolves to an HTTP response.
*/
async write({
url,
json,
headers = {},
capability
capability,
authzHeaderName = 'authorization'
} = {}) {
return this.request({
url, capability, method: 'post', action: 'write', headers, json
url, capability, method: 'post', action: 'write', headers, json, authzHeaderName
});
}
}
Expand Down