UNPKG

827 BJavaScriptView Raw
1//
2// OAuth authentication class
3//
4var oauth = require('oauth')
5
6var required = [
7 'oauth_request_url'
8 , 'oauth_access_url'
9 , 'consumer_key'
10 , 'consumer_secret'
11 , 'access_token'
12 , 'access_token_secret'
13];
14
15//
16// OAuth Authentication Object
17//
18function Auth (config) {
19 //check config for proper format
20 if (typeof config !== 'object')
21 throw new TypeError('config must be object, got ' + typeof config)
22
23 required.forEach(function (requirement) {
24 if (!config[requirement])
25 throw new Error('config must provide ' + requirement)
26 })
27
28 //assign config
29 this.config = config
30 this.oa = new oauth.OAuth(
31 config.oauth_request_url
32 , config.oauth_access_url
33 , config.consumer_key
34 , config.consumer_secret
35 , '1.0'
36 , null
37 , 'HMAC-SHA1'
38 )
39}
40
41module.exports = Auth
42