Examples > password-catalog PLUGIN.JS (1/5) File: examples/plugins/password-catalog/plugin.js (99 lines) // password-catalog: web setup for a device.json catalog that signs in with // username + password (auth.type "password"). // // The browser only collects and tests the credentials. It writes: // config.json {server, username, password} -> {cfg.*} on the device // token.json {token: "..."} -> {token} on the device // The reader re-mints the token by itself whenever the server answers 401/403. // // To adapt: change TOKEN_PATH / loginRequest() to match your server, and keep // device.json's auth.request identical to loginRequest(). const REQUIRED_CAPS = ['catalog.list_index_mapping', 'catalog.encoded_item_fields', 'catalog.server_paths']; function loginRequest(cfg) { return { method: 'POST', url: cfg.server + '/oauth/token', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: cfg.username, password: cfg.password }), }; } const tokenFrom = (json) => json && json.access_token; Next: 06 plugin.js (2/5)