Socket
Socket
Sign inDemoInstall

wikidata-token

Package Overview
Dependencies
57
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.0 to 2.3.0

edit.js

3

CHANGELOG.md
# CHANGELOG
*versions follow [SemVer](http://semver.org)*
## 2.3.0 - 2017-05-21
* Added [support for OAuth](https://github.com/maxlath/wikidata-token#with-username--password)
## 2.2.0 - 2017-03-29

@@ -5,0 +8,0 @@ * Added a `wikibaseInstance` option to allow using it on a different Wikibase instance

module.exports = {
username: 'your-wikidata-username',
password: 'your-wikidata-password'
credentials: {
username: 'your-wikidata-username',
password: 'your-wikidata-password'
},
oauth: {
consumer_key: 'your-consumer-token',
consumer_secret: 'your-secret-token',
token: 'a-user-token',
token_secret: 'a-secret-token'
}
}

24

lib/get_token_getter.js

@@ -1,14 +0,18 @@

const got = require('got')
const breq = require('bluereq')
const getInstance = require('./get_instance')
const getToken = (instance) => (loginCookies) => {
const url = `${instance}?action=query&meta=tokens&format=json`
const headers = { 'cookie': loginCookies }
return got.get(url, { headers })
.then(parseTokens.bind(null, loginCookies))
const getToken = (instance, oauth) => loginCookies => {
const params = { url: `${instance}?action=query&meta=tokens&format=json` }
if (oauth) {
params.oauth = oauth
} else {
params.headers = { 'cookie': loginCookies }
}
return breq.get(params)
.then(parseTokens(loginCookies))
}
const parseTokens = (loginCookies, res) => {
const parseTokens = loginCookies => res => {
return {
token: JSON.parse(res.body).query.tokens.csrftoken,
token: res.body.query.tokens.csrftoken,
cookie: loginCookies

@@ -18,5 +22,5 @@ }

module.exports = (config, loginCookiesPromise) => {
module.exports = (config, loginCookiesPromise, oauth) => {
const instance = getInstance(config)
return () => loginCookiesPromise.then(getToken(instance))
return () => loginCookiesPromise.then(getToken(instance, oauth))
}

@@ -1,2 +0,2 @@

const got = require('got')
const breq = require('bluereq')
const _ = require('./utils')

@@ -6,2 +6,3 @@ const pkg = require('../package.json')

const defaultUserAgent = `wikidata-token/${pkg.version} (${pkg.repository.url})`
const qs = require('querystring')

@@ -11,3 +12,4 @@ module.exports = (config) => {

const headers = {
'user-agent': config.userAgent || defaultUserAgent
'user-agent': config.userAgent || defaultUserAgent,
'content-type': 'application/x-www-form-urlencoded'
}

@@ -23,7 +25,7 @@ const instance = getInstance(config)

const getLoginToken = () => {
const body = {
const body = qs.stringify({
lgname: username,
lgpassword: password
}
return got.post(loginUrl, { json: true, headers, body })
})
return breq.post({ url: loginUrl, headers, body })
.then(parseLoginToken)

@@ -43,11 +45,11 @@ }

const { cookies, token } = data
const body = {
const body = qs.stringify({
lgname: username,
lgpassword: password,
lgtoken: token
}
})
const headersWithCookies = Object.assign({}, headers, { 'Cookie': cookies })
return got.post(loginUrl, { json: true, headers: headersWithCookies, body })
return breq.post({ url: loginUrl, headers: headersWithCookies, body })
.then(res => {

@@ -54,0 +56,0 @@ if (verbose) console.log('reallyLogin res', res.body)

{
"name": "wikidata-token",
"version": "2.2.0",
"version": "2.3.0",
"description": "a promises-based lib abstracting authentification for write actions on the Wikidata API",

@@ -15,4 +15,4 @@ "main": "wikidata-token.js",

"dependencies": {
"chalk": "^1.1.3",
"got": "^6.7.1"
"bluereq": "^2.1.2",
"chalk": "^1.1.3"
},

@@ -19,0 +19,0 @@ "devDependencies": {

@@ -11,2 +11,4 @@ a promises-based lib abstracting authentification for write actions on the [Wikidata API](https://www.wikidata.org/w/api.php)

- [use](#use)
- [with username / password](#with-username--password)
- [with OAuth](#with-oauth)
- [Example](#example)

@@ -29,2 +31,5 @@ - [Development](#development)

### use
#### with username / password
```javascript

@@ -42,3 +47,2 @@ var config = {

var getToken = wdToken(config)
```

@@ -61,2 +65,22 @@

#### with OAuth
same as with username / password but your config object will look like:
```js
var config = {
// Required
oauth: {
// Obtained at registration
// https://www.mediawiki.org/wiki/OAuth/For_Developers#Registration
consumer_key: 'your-consumer-token',
consumer_secret: 'your-secret-token',
// Obtained when the user authorized your service
// see https://www.mediawiki.org/wiki/OAuth/For_Developers#Authorization
token: 'a-user-token',
token_secret: 'a-secret-token'
},
// Then the optional parameters are the same
}
```
## Example

@@ -63,0 +87,0 @@

@@ -5,4 +5,4 @@ const test = require('ava')

test('wikidata-token works', t => {
const tokenGetter = wikidataToken(CONFIG)
test('get token from username and password', t => {
const tokenGetter = wikidataToken(CONFIG.credentials)
t.is(typeof tokenGetter, 'function')

@@ -22,1 +22,12 @@

})
test('get token from oauth', t => {
const { oauth } = CONFIG
const tokenGetter = wikidataToken({ oauth })
t.is(typeof tokenGetter, 'function')
return tokenGetter()
.then(res => {
t.true(res.token.length > 40)
})
})

@@ -5,4 +5,11 @@ const login = require('./lib/login')

module.exports = (config) => {
const loginCookiesPromise = login(config)
return getTokenGetter(config, loginCookiesPromise)
if (config.oauth) {
const loginCookiesPromise = Promise.resolve('')
return getTokenGetter(config, loginCookiesPromise, config.oauth)
} else if (config.username && config.password) {
const loginCookiesPromise = login(config)
return getTokenGetter(config, loginCookiesPromise)
} else {
throw new Error('no authentification means provided')
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc