1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-17 17:10:05 +00:00

fix(viya): updated getAccessTokenForViya with headers based on latest docs

This commit is contained in:
Saad Jutt
2022-03-01 17:42:28 +05:00
parent 1ee07eeecf
commit 96cb77da45

View File

@@ -1,6 +1,5 @@
import { SasAuthResponse } from '@sasjs/utils/types' import { SasAuthResponse } from '@sasjs/utils/types'
import { prefixMessage } from '@sasjs/utils/error' import { prefixMessage } from '@sasjs/utils/error'
import * as NodeFormData from 'form-data'
import { RequestClient } from '../request/RequestClient' import { RequestClient } from '../request/RequestClient'
/** /**
@@ -24,26 +23,17 @@ export async function getAccessTokenForViya(
token = Buffer.from(clientId + ':' + clientSecret).toString('base64') token = Buffer.from(clientId + ':' + clientSecret).toString('base64')
} }
const headers = { const headers = {
Authorization: 'Basic ' + token Authorization: 'Basic ' + token,
Accept: 'application/json'
} }
let formData const data = new URLSearchParams({
if (typeof FormData === 'undefined') { grant_type: 'authorization_code',
formData = new NodeFormData() code: authCode
} else { })
formData = new FormData()
}
formData.append('grant_type', 'authorization_code')
formData.append('code', authCode)
const authResponse = await requestClient const authResponse = await requestClient
.post( .post(url, data, undefined, 'application/x-www-form-urlencoded', headers)
url,
formData,
undefined,
'multipart/form-data; boundary=' + (formData as any)._boundary,
headers
)
.then((res) => res.result as SasAuthResponse) .then((res) => res.result as SasAuthResponse)
.catch((err) => { .catch((err) => {
throw prefixMessage(err, 'Error while getting access token. ') throw prefixMessage(err, 'Error while getting access token. ')