-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokenCall.js
More file actions
34 lines (29 loc) · 976 Bytes
/
tokenCall.js
File metadata and controls
34 lines (29 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* eslint-disable func-names */
const api = require('./api')
module.exports = (function () {
console.warn('⚠️ @kth/api-call/tokenCall is deprecated and will be removed ⚠️')
function TokenCall(options) {
this.options = options || {}
this.options.tokenEndpoint = options.tokenEndpoint
this.options.clientKey = options.clientKey
this.options.clientSecret = options.clientSecret
}
function factory(options) {
return new TokenCall(options)
}
TokenCall.prototype.getClientToken = function (onSuccess, onError) {
const parsedTokenUrl = new URL(this.options.tokenEndpoint)
const TokenApi = api({
host: parsedTokenUrl.host,
port: parsedTokenUrl.port,
path: parsedTokenUrl.pathname,
query: {
grant_type: 'client_credential',
client_id: this.options.clientKey,
client_secret: this.options.clientSecret,
},
})
TokenApi.request(onSuccess, onError)
}
return factory
})()