@sasjs/adapter 3.7.7 → 3.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -80,5 +80,5 @@
80
80
  "https": "1.0.0",
81
81
  "tough-cookie": "4.0.0"
82
82
  },
83
- "version": "3.7.7"
83
+ "version": "3.7.8"
84
84
  }
@@ -1,6 +1,5 @@
1
1
  import { SasAuthResponse } from '@sasjs/utils/types'
2
2
  import { prefixMessage } from '@sasjs/utils/error'
3
- import * as NodeFormData from 'form-data'
4
3
  import { RequestClient } from '../request/RequestClient'
5
4
 
6
5
  /**
@@ -24,26 +23,17 @@ export async function getAccessTokenForViya(
24
23
  token = Buffer.from(clientId + ':' + clientSecret).toString('base64')
25
24
  }
26
25
  const headers = {
27
- Authorization: 'Basic ' + token
26
+ Authorization: 'Basic ' + token,
27
+ Accept: 'application/json'
28
28
  }
29
29
 
30
- let formData
31
- if (typeof FormData === 'undefined') {
32
- formData = new NodeFormData()
33
- } else {
34
- formData = new FormData()
35
- }
36
- formData.append('grant_type', 'authorization_code')
37
- formData.append('code', authCode)
30
+ const data = new URLSearchParams({
31
+ grant_type: 'authorization_code',
32
+ code: authCode
33
+ })
38
34
 
39
35
  const authResponse = await requestClient
40
- .post(
41
- url,
42
- formData,
43
- undefined,
44
- 'multipart/form-data; boundary=' + (formData as any)._boundary,
45
- headers
46
- )
36
+ .post(url, data, undefined, 'application/x-www-form-urlencoded', headers)
47
37
  .then((res) => res.result as SasAuthResponse)
48
38
  .catch((err) => {
49
39
  throw prefixMessage(err, 'Error while getting access token. ')