wikibase-token
A promises-based lib abstracting authentification for write requests on a Wikibase API.
See Wikidata API for API reference.
This package was primarily published as wikidata-token
but has now being generalized to support any Wikibase instance: wikidata.org among others.
Summary
How To
install
npm install wikibase-token
use
with username / password
var config = {
instance: 'https://mywikibase.instance',
username: 'myUsername',
password: 'pa55word',
verbose: true,
userAgent: `your-module/${pkg.version} (https://git.repo/username/your-module)`
}
var wbToken = require('wikibase-token')
var getToken = wbToken(config)
getToken
is then a function, which when called returns an ES6 promise that shoud resolve to something looking like:
{
token: 'eb974a8adc9abacf7c9f3f94763ad92e51d76e57+\\',
cookie: 'a very long cookie with your session data'
}
Your request header should then look like:
'cookie': cookie
'content-type': 'application/x-www-form-urlencoded'
and the token should then be passed in the body of your request as form data (thus the x-www-form-urlencoded
header) and NOT JSON (this one got me crazy and made me realize that there was a time JSON wasn't obvious..! poor elders of the Internet), in addition with the other field expected by the API action you're using: contrary to what the API documentation seem to indicate, for POST action, parameters are passed in the body and not in the url (out of action
and format
)
with OAuth
same as with username / password but your config object will look like:
var config = {
instance: 'https://mywikibase.instance',
oauth: {
consumer_key: 'your-consumer-token',
consumer_secret: 'your-secret-token',
token: 'a-user-token',
token_secret: 'a-secret-token'
},
}
Example
Development
To run the tests, make sure to create a config/local.js
overriding config/default.js
with the username and password of a Wikibase instance
Donate
We are developing and maintaining tools to work with Wikidata from NodeJS, the browser, or simply the command line, with quality and ease of use at heart. Any donation will be interpreted as a "please keep going, your work is very much needed and awesome. PS: love". Donate
See Also
You may also like
Do you know inventaire.io? It's a web app to share books with your friends, built on top of Wikidata! And its libre software too.
License
MIT