mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 03:34:35 +00:00
fix: reqHeadrs.txt will contain headers to access APIs
This commit is contained in:
@@ -3,7 +3,7 @@ import { Request, Security, Route, Tags, Post, Body } from 'tsoa'
|
|||||||
import { ExecuteReturnJson, ExecutionController } from './internal'
|
import { ExecuteReturnJson, ExecutionController } from './internal'
|
||||||
import { PreProgramVars } from '../types'
|
import { PreProgramVars } from '../types'
|
||||||
import { ExecuteReturnJsonResponse } from '.'
|
import { ExecuteReturnJsonResponse } from '.'
|
||||||
import { parseLogToArray } from '../utils'
|
import { getPreProgramVariables, parseLogToArray } from '../utils'
|
||||||
|
|
||||||
interface ExecuteSASCodePayload {
|
interface ExecuteSASCodePayload {
|
||||||
/**
|
/**
|
||||||
@@ -56,16 +56,3 @@ const executeSASCode = async (req: any, { code }: ExecuteSASCodePayload) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPreProgramVariables = (req: any): PreProgramVars => {
|
|
||||||
const host = req.get('host')
|
|
||||||
const protocol = req.protocol + '://'
|
|
||||||
const { user, accessToken } = req
|
|
||||||
return {
|
|
||||||
username: user.username,
|
|
||||||
userId: user.userId,
|
|
||||||
displayName: user.displayName,
|
|
||||||
serverUrl: protocol + host,
|
|
||||||
accessToken
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -75,12 +75,12 @@ export class ExecutionController {
|
|||||||
const logPath = path.join(session.path, 'log.log')
|
const logPath = path.join(session.path, 'log.log')
|
||||||
const headersPath = path.join(session.path, 'stpsrv_header.txt')
|
const headersPath = path.join(session.path, 'stpsrv_header.txt')
|
||||||
const weboutPath = path.join(session.path, 'webout.txt')
|
const weboutPath = path.join(session.path, 'webout.txt')
|
||||||
const tokenFile = path.join(session.path, 'accessToken.txt')
|
const tokenFile = path.join(session.path, 'reqHeaders.txt')
|
||||||
|
|
||||||
await createFile(weboutPath, '')
|
await createFile(weboutPath, '')
|
||||||
await createFile(
|
await createFile(
|
||||||
tokenFile,
|
tokenFile,
|
||||||
preProgramVariables?.accessToken ?? 'accessToken'
|
preProgramVariables?.httpHeaders.join('\n') ?? ''
|
||||||
)
|
)
|
||||||
|
|
||||||
const varStatments = Object.keys(vars).reduce(
|
const varStatments = Object.keys(vars).reduce(
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ import {
|
|||||||
ExecutionController,
|
ExecutionController,
|
||||||
ExecutionVars
|
ExecutionVars
|
||||||
} from './internal'
|
} from './internal'
|
||||||
import { PreProgramVars } from '../types'
|
|
||||||
import {
|
import {
|
||||||
|
getPreProgramVariables,
|
||||||
getTmpFilesFolderPath,
|
getTmpFilesFolderPath,
|
||||||
HTTPHeaders,
|
HTTPHeaders,
|
||||||
isDebugOn,
|
isDebugOn,
|
||||||
@@ -210,16 +210,3 @@ const executeReturnJson = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPreProgramVariables = (req: any): PreProgramVars => {
|
|
||||||
const host = req.get('host')
|
|
||||||
const protocol = req.protocol + '://'
|
|
||||||
const { user, accessToken } = req
|
|
||||||
return {
|
|
||||||
username: user.username,
|
|
||||||
userId: user.userId,
|
|
||||||
displayName: user.displayName,
|
|
||||||
serverUrl: protocol + host,
|
|
||||||
accessToken
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ export interface PreProgramVars {
|
|||||||
userId: number
|
userId: number
|
||||||
displayName: string
|
displayName: string
|
||||||
serverUrl: string
|
serverUrl: string
|
||||||
accessToken: string
|
httpHeaders: string[]
|
||||||
}
|
}
|
||||||
|
|||||||
23
api/src/utils/getPreProgramVariables.ts
Normal file
23
api/src/utils/getPreProgramVariables.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { PreProgramVars } from '../types'
|
||||||
|
|
||||||
|
export const getPreProgramVariables = (req: any): PreProgramVars => {
|
||||||
|
const host = req.get('host')
|
||||||
|
const protocol = req.protocol + '://'
|
||||||
|
const { user, accessToken } = req
|
||||||
|
const csrfToken = req.headers['x-xsrf-token']
|
||||||
|
const sessionId = req.cookies['connect.sid']
|
||||||
|
|
||||||
|
const httpHeaders: string[] = []
|
||||||
|
|
||||||
|
if (accessToken) httpHeaders.push(`Authorization: Bearer ${accessToken}`)
|
||||||
|
if (csrfToken) httpHeaders.push(`x-xsrf-token: ${csrfToken}`)
|
||||||
|
if (sessionId) httpHeaders.push(`cookie: connect.sid=${sessionId}`)
|
||||||
|
|
||||||
|
return {
|
||||||
|
username: user.username,
|
||||||
|
userId: user.userId,
|
||||||
|
displayName: user.displayName,
|
||||||
|
serverUrl: protocol + host,
|
||||||
|
httpHeaders
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ export * from './generateAuthCode'
|
|||||||
export * from './generateRefreshToken'
|
export * from './generateRefreshToken'
|
||||||
export * from './getCertificates'
|
export * from './getCertificates'
|
||||||
export * from './getDesktopFields'
|
export * from './getDesktopFields'
|
||||||
|
export * from './getPreProgramVariables'
|
||||||
export * from './isDebugOn'
|
export * from './isDebugOn'
|
||||||
export * from './parseLogToArray'
|
export * from './parseLogToArray'
|
||||||
export * from './removeTokensInDB'
|
export * from './removeTokensInDB'
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
### Get current user's info via access token
|
### Get current user's info via session ID
|
||||||
GET http://localhost:5000/SASjsApi/session
|
GET http://localhost:5000/SASjsApi/session
|
||||||
|
cookie: connect.sid=s:G2DeFdKuWhnmTOsTHmTWrxAXPx2P6TLD.JyNLxfACC1w3NlFQFfL5chyxtrqbPYmS6iButRc1goE
|
||||||
Reference in New Issue
Block a user