Clean code
This commit is contained in:
parent
04bd9dda9c
commit
099cc145bf
|
@ -19,12 +19,7 @@ export function doInIdentityContext(identity: IdentityContext, task: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// used in server/worker
|
// used in server/worker
|
||||||
export function doInUserContext(
|
export function doInUserContext(user: User, ctx: Ctx, task: any) {
|
||||||
user: User,
|
|
||||||
ctx: Ctx,
|
|
||||||
task: any,
|
|
||||||
isScim: boolean
|
|
||||||
) {
|
|
||||||
const userContext: UserContext = {
|
const userContext: UserContext = {
|
||||||
...user,
|
...user,
|
||||||
_id: user._id as string,
|
_id: user._id as string,
|
||||||
|
@ -34,7 +29,6 @@ export function doInUserContext(
|
||||||
// filled in by koa-useragent package
|
// filled in by koa-useragent package
|
||||||
userAgent: ctx.userAgent._agent.source,
|
userAgent: ctx.userAgent._agent.source,
|
||||||
},
|
},
|
||||||
isScimCall: isScim,
|
|
||||||
}
|
}
|
||||||
return doInIdentityContext(userContext, task)
|
return doInIdentityContext(userContext, task)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import {
|
||||||
clearCookie,
|
clearCookie,
|
||||||
openJwt,
|
openJwt,
|
||||||
isValidInternalAPIKey,
|
isValidInternalAPIKey,
|
||||||
isScimEndpoint,
|
|
||||||
} from "../utils"
|
} from "../utils"
|
||||||
import { getUser } from "../cache/user"
|
import { getUser } from "../cache/user"
|
||||||
import { getSession, updateSessionTTL } from "../security/sessions"
|
import { getSession, updateSessionTTL } from "../security/sessions"
|
||||||
|
@ -106,8 +105,6 @@ export default function (
|
||||||
apiKey = ctx.request.headers[Header.AUTHORIZATION].split(" ")[1]
|
apiKey = ctx.request.headers[Header.AUTHORIZATION].split(" ")[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
const isScimCall = isScimEndpoint(ctx)
|
|
||||||
|
|
||||||
const tenantId = ctx.request.headers[Header.TENANT_ID]
|
const tenantId = ctx.request.headers[Header.TENANT_ID]
|
||||||
let authenticated = false,
|
let authenticated = false,
|
||||||
user = null,
|
user = null,
|
||||||
|
@ -171,7 +168,7 @@ export default function (
|
||||||
finalise(ctx, { authenticated, user, internal, version, publicEndpoint })
|
finalise(ctx, { authenticated, user, internal, version, publicEndpoint })
|
||||||
|
|
||||||
if (user && user.email) {
|
if (user && user.email) {
|
||||||
return identity.doInUserContext(user, ctx, next, isScimCall)
|
return identity.doInUserContext(user, ctx, next)
|
||||||
} else {
|
} else {
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
import { Ctx } from "@budibase/types"
|
|
||||||
|
|
||||||
const SCIM_ENDPOINTS = new RegExp(["scim/"].join("|"))
|
|
||||||
export function isScimEndpoint(ctx: Ctx): boolean {
|
|
||||||
return SCIM_ENDPOINTS.test(ctx.request.url)
|
|
||||||
}
|
|
|
@ -1,3 +1,2 @@
|
||||||
export * from "./hashing"
|
export * from "./hashing"
|
||||||
export * from "./utils"
|
export * from "./utils"
|
||||||
export * from "./endpointUtils"
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ export interface UserContext extends BaseContext, User {
|
||||||
tenantId: string
|
tenantId: string
|
||||||
account?: Account
|
account?: Account
|
||||||
hostInfo: HostInfo
|
hostInfo: HostInfo
|
||||||
isScimCall?: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IdentityContext = BaseContext | AccountUserContext | UserContext
|
export type IdentityContext = BaseContext | AccountUserContext | UserContext
|
||||||
|
|
Loading…
Reference in New Issue