mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-15 08:00:05 +00:00
fix(refreshTokensForViya): fixed FormData logic
This commit is contained in:
@@ -29,9 +29,12 @@ export async function getTokens(
|
|||||||
const error =
|
const error =
|
||||||
'Unable to obtain new access token. Your refresh token has expired.'
|
'Unable to obtain new access token. Your refresh token has expired.'
|
||||||
logger.error(error)
|
logger.error(error)
|
||||||
|
|
||||||
throw new Error(error)
|
throw new Error(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info('Refreshing access and refresh tokens.')
|
logger.info('Refreshing access and refresh tokens.')
|
||||||
|
|
||||||
const tokens =
|
const tokens =
|
||||||
serverType === ServerType.SasViya
|
serverType === ServerType.SasViya
|
||||||
? await refreshTokensForViya(
|
? await refreshTokensForViya(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ 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 * as NodeFormData from 'form-data'
|
||||||
import { RequestClient } from '../request/RequestClient'
|
import { RequestClient } from '../request/RequestClient'
|
||||||
|
import { isNode } from '../utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exchanges the refresh token for an access token for the given client.
|
* Exchanges the refresh token for an access token for the given client.
|
||||||
@@ -17,8 +18,7 @@ export async function refreshTokensForViya(
|
|||||||
refreshToken: string
|
refreshToken: string
|
||||||
) {
|
) {
|
||||||
const url = '/SASLogon/oauth/token'
|
const url = '/SASLogon/oauth/token'
|
||||||
let token
|
const token =
|
||||||
token =
|
|
||||||
typeof Buffer === 'undefined'
|
typeof Buffer === 'undefined'
|
||||||
? btoa(clientId + ':' + clientSecret)
|
? btoa(clientId + ':' + clientSecret)
|
||||||
: Buffer.from(clientId + ':' + clientSecret).toString('base64')
|
: Buffer.from(clientId + ':' + clientSecret).toString('base64')
|
||||||
@@ -27,8 +27,7 @@ export async function refreshTokensForViya(
|
|||||||
Authorization: 'Basic ' + token
|
Authorization: 'Basic ' + token
|
||||||
}
|
}
|
||||||
|
|
||||||
const formData =
|
const formData = isNode() ? new NodeFormData() : new FormData()
|
||||||
typeof FormData === 'undefined' ? new NodeFormData() : new FormData()
|
|
||||||
formData.append('grant_type', 'refresh_token')
|
formData.append('grant_type', 'refresh_token')
|
||||||
formData.append('refresh_token', refreshToken)
|
formData.append('refresh_token', refreshToken)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user