0.2.1 • Published 6 years ago

macaroon-bakery v0.2.1

Weekly downloads
11
License
LGPL-3.0
Repository
github
Last release
6 years ago

view on npm npm module downloads

bakeryjs

API Reference

bakeryjs.

Example

import { Bakery } from "@canonical/macaroon-bakery";
const bakery = new Bakery();

bakery.get(url, headers, callback)

bakeryjs~Bakery

A macaroon bakery implementation.

The bakery implements the protocol used to acquire and discharge macaroons over HTTP.

Kind: inner class of bakeryjs

new Bakery(config)

Initialize a macaroon bakery with the given parameters.

ParamTypeDescription
configObjectoptional config.
config.onSuccessfunctiona function to be called when the request completes properly.
config.storagefunctionthe storage used to persist macaroons. It must implement the following interface:
config.storage.getfunctionget(key) -> value.
config.storage.setfunctionset(key, value, callback): the callback is called without arguments when the set operation has been performed. If not provided, it defaults to BakeryStorage using an in memory store.
config.visitPagefunctionthe function used to visit the identity provider page when required, defaulting to opening a pop up window. It receives an error object.
config.visitPage.InfoObjectan object containing relevant info for the visit handling.
config.visitPage.Info.WaitUrlStringthe url to wait on for IdM discharge.
config.visitPage.Info.VisitUrlStringthe url to visit to authenticate with the IdM.
config.visitPage.jujuguifunctionan optional value specifying a method to use against idm to authenticate. Used in non interactive authentication scenarios.
config.sendRequestfunctiona function used to make XHR HTTP requests, with the following signature: func(path, method, headers, body, withCredentials, callback) -> xhr. By default an internal function is used. This is mostly for testing.

bakery.sendRequest(url, method, headers, body, callback) ⇒ Object

Send an HTTP request to the given URL with the given HTTP method, headers and body. The given callback receives an error and a response when the request is complete.

Kind: instance method of Bakery
Returns: Object - the XHR instance.

ParamTypeDescription
urlStringThe URL to which to send the request.
methodStringThe HTTP method, like "get" or "POST".
headersObjectHeaders that must be included in the request. Note that bakery specific headers are automatically added internally.
bodyStringThe request body if it applies, or null.
callbackfunctionA function called when the response is received from the remote URL. It receives a tuple (error, response). If the request succeeds the error is null.

bakery.get()

Send an HTTP GET request to the given URL with the given headers. The given callback receives an error and a response when the request is complete.

See the "sendRequest" method above for a description of the parameters.

Kind: instance method of Bakery

bakery.delete()

Send an HTTP DELETE request to the given URL with the given headers and body. The given callback receives an error and a response when the request is complete.

See the "sendRequest" method above for a description of the parameters.

Kind: instance method of Bakery

bakery.post()

Send an HTTP POST request to the given URL with the given headers and body. The given callback receives an error and a response when the request is complete.

See the "sendRequest" method above for a description of the parameters.

Kind: instance method of Bakery

bakery.put()

Send an HTTP PUT request to the given URL with the given headers and body. The given callback receives an error and a response when the request is complete.

See the "sendRequest" method above for a description of the parameters.

Kind: instance method of Bakery

bakery.patch()

Send an HTTP PATCH request to the given URL with the given headers and body. The given callback receives an error and a response when the request is complete.

See the "sendRequest" method above for a description of the parameters.

Kind: instance method of Bakery

bakery.discharge(macaroon, onSuccess, onFailure)

Discharge the given macaroon. Acquire any third party discharges.

Kind: instance method of Bakery

ParamTypeDescription
macaroonObjectThe decoded macaroon to be discharged.
onSuccessfunctionThe function to be called if the discharge succeeds. It receives the resulting macaroons array.
onFailurefunctionThe function to be called if the discharge fails. It receives an error message.

bakeryjs~BakeryStorage

A storage for the macaroon bakery.

The storage is used to persist macaroons.

Kind: inner class of bakeryjs

new BakeryStorage(store, config)

Initialize a bakery storage with the given underlaying store and params.

ParamTypeDescription
storeObjectA store object implement the following interface: - getItem(key) -> value; - setItem(key, value); - clear().
configObjectOptional configuration.
config.initialObjecta map of key/value pairs that must be initially included in
config.servicesObjecta map of service names (like "charmstore" or "terms") to the base URL of their corresponding API endpoints. This is used to simplify and reduce the URLs passed as keys to the storage.
config.charmstoreCookieSetterfunctiona function that can be used to register macaroons to the charm store service. The function accepts a value and a callback, which receives an error and a response.

bakeryStorage.get(key) ⇒ String

Retrieve and return the value for the provided key.

Kind: instance method of BakeryStorage
Returns: String - The corresponding value, usually a serialized macaroon.

ParamTypeDescription
keyStringThe storage key, usually a URL.

bakeryStorage.set(key, value, callback)

Store the given value in the given storage key.

Call the callback when done.

Kind: instance method of BakeryStorage

ParamTypeDescription
keyStringThe storage key, usually a URL.
valueStringThe value, usually a serialized macaroon.
callbackfunctionA function called without arguments when the value is properly stored.

bakeryStorage.clear()

Remove all key/value pairs from the storage.

Kind: instance method of BakeryStorage

bakeryjs~InMemoryStore

An in-memory store for the BakeryStorage.

Kind: inner class of bakeryjs

bakeryjs~serialize(macaroons) ⇒ string

Serialize the given macaroons.

Kind: inner method of bakeryjs
Returns: string - The resulting serialized string.

ParamTypeDescription
macaroonsArrayThe macaroons to be serialized.

bakeryjs~deserialize(serialized) ⇒ Array

De-serialize the given serialized macaroons.

Kind: inner method of bakeryjs
Returns: Array - The resulting macaroon slice.

ParamTypeDescription
serializedstringThe serialized macaroons.