Unnest
This commit is contained in:
parent
c1fe41a588
commit
542594baeb
|
@ -381,32 +381,37 @@ export class RestIntegration implements IntegrationBase {
|
||||||
authConfigId?: string,
|
authConfigId?: string,
|
||||||
authConfigType?: RestAuthType
|
authConfigType?: RestAuthType
|
||||||
): Promise<{ [key: string]: any }> {
|
): Promise<{ [key: string]: any }> {
|
||||||
let headers: any = {}
|
if (!authConfigId) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
if (authConfigId) {
|
if (authConfigType === RestAuthType.OAUTH2) {
|
||||||
if (authConfigType === RestAuthType.OAUTH2) {
|
return { Authorization: await sdk.oauth2.generateToken(authConfigId) }
|
||||||
headers.Authorization = await sdk.oauth2.generateToken(authConfigId)
|
}
|
||||||
} else if (this.config.authConfigs) {
|
|
||||||
const authConfig = this.config.authConfigs.filter(
|
if (!this.config.authConfigs) {
|
||||||
c => c._id === authConfigId
|
return {}
|
||||||
)[0]
|
}
|
||||||
// check the config still exists before proceeding
|
|
||||||
// if not - do nothing
|
let headers: any = {}
|
||||||
if (authConfig) {
|
const authConfig = this.config.authConfigs.filter(
|
||||||
const { type, config } = authConfig
|
c => c._id === authConfigId
|
||||||
switch (type) {
|
)[0]
|
||||||
case RestAuthType.BASIC:
|
// check the config still exists before proceeding
|
||||||
headers.Authorization = `Basic ${Buffer.from(
|
// if not - do nothing
|
||||||
`${config.username}:${config.password}`
|
if (authConfig) {
|
||||||
).toString("base64")}`
|
const { type, config } = authConfig
|
||||||
break
|
switch (type) {
|
||||||
case RestAuthType.BEARER:
|
case RestAuthType.BASIC:
|
||||||
headers.Authorization = `Bearer ${config.token}`
|
headers.Authorization = `Basic ${Buffer.from(
|
||||||
break
|
`${config.username}:${config.password}`
|
||||||
default:
|
).toString("base64")}`
|
||||||
throw utils.unreachable(type)
|
break
|
||||||
}
|
case RestAuthType.BEARER:
|
||||||
}
|
headers.Authorization = `Bearer ${config.token}`
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
throw utils.unreachable(type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue