mirror of
https://github.com/sasjs/server.git
synced 2025-12-08 02:42:44 +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 { PreProgramVars } from '../types'
|
||||
import { ExecuteReturnJsonResponse } from '.'
|
||||
import { parseLogToArray } from '../utils'
|
||||
import { getPreProgramVariables, parseLogToArray } from '../utils'
|
||||
|
||||
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 headersPath = path.join(session.path, 'stpsrv_header.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(
|
||||
tokenFile,
|
||||
preProgramVariables?.accessToken ?? 'accessToken'
|
||||
preProgramVariables?.httpHeaders.join('\n') ?? ''
|
||||
)
|
||||
|
||||
const varStatments = Object.keys(vars).reduce(
|
||||
|
||||
@@ -17,8 +17,8 @@ import {
|
||||
ExecutionController,
|
||||
ExecutionVars
|
||||
} from './internal'
|
||||
import { PreProgramVars } from '../types'
|
||||
import {
|
||||
getPreProgramVariables,
|
||||
getTmpFilesFolderPath,
|
||||
HTTPHeaders,
|
||||
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
|
||||
displayName: 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 './getCertificates'
|
||||
export * from './getDesktopFields'
|
||||
export * from './getPreProgramVariables'
|
||||
export * from './isDebugOn'
|
||||
export * from './parseLogToArray'
|
||||
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
|
||||
cookie: connect.sid=s:G2DeFdKuWhnmTOsTHmTWrxAXPx2P6TLD.JyNLxfACC1w3NlFQFfL5chyxtrqbPYmS6iButRc1goE
|
||||
Reference in New Issue
Block a user