@budibase/worker 1.0.212-alpha.12 → 1.0.212-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "1.0.212-alpha.
|
|
4
|
+
"version": "1.0.212-alpha.15",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"author": "Budibase",
|
|
35
35
|
"license": "GPL-3.0",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@budibase/backend-core": "^1.0.212-alpha.
|
|
38
|
-
"@budibase/pro": "1.0.212-alpha.
|
|
39
|
-
"@budibase/string-templates": "^1.0.212-alpha.
|
|
40
|
-
"@budibase/types": "^1.0.212-alpha.
|
|
37
|
+
"@budibase/backend-core": "^1.0.212-alpha.15",
|
|
38
|
+
"@budibase/pro": "1.0.212-alpha.14",
|
|
39
|
+
"@budibase/string-templates": "^1.0.212-alpha.15",
|
|
40
|
+
"@budibase/types": "^1.0.212-alpha.15",
|
|
41
41
|
"@koa/router": "8.0.8",
|
|
42
42
|
"@sentry/node": "6.17.7",
|
|
43
43
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"./scripts/jestSetup.js"
|
|
101
101
|
]
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "95300e2d7101504da960c7a4f2c9cdf06e3058a5"
|
|
104
104
|
}
|
|
@@ -1,49 +1,22 @@
|
|
|
1
1
|
const core = require("@budibase/backend-core")
|
|
2
|
-
const { getScopedConfig } = require("@budibase/backend-core/db")
|
|
3
|
-
const { google } = require("@budibase/backend-core/middleware")
|
|
4
|
-
const { oidc } = require("@budibase/backend-core/middleware")
|
|
5
2
|
const { Configs, EmailTemplatePurpose } = require("../../../constants")
|
|
6
3
|
const { sendEmail, isEmailConfigured } = require("../../../utilities/email")
|
|
7
4
|
const { setCookie, getCookie, clearCookie, hash, platformLogout } = core.utils
|
|
8
5
|
const { Cookies, Headers } = core.constants
|
|
9
|
-
const { passport } = core.auth
|
|
6
|
+
const { passport, ssoCallbackUrl, google, oidc } = core.auth
|
|
10
7
|
const { checkResetPasswordCode } = require("../../../utilities/redis")
|
|
11
|
-
const {
|
|
12
|
-
getGlobalDB,
|
|
13
|
-
getTenantId,
|
|
14
|
-
isMultiTenant,
|
|
15
|
-
} = require("@budibase/backend-core/tenancy")
|
|
8
|
+
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
16
9
|
const env = require("../../../environment")
|
|
17
10
|
import { events, users as usersCore, context } from "@budibase/backend-core"
|
|
18
11
|
import { users } from "../../../sdk"
|
|
19
12
|
import { User } from "@budibase/types"
|
|
20
13
|
|
|
21
|
-
const ssoCallbackUrl = async (config: any, type: any) => {
|
|
22
|
-
// incase there is a callback URL from before
|
|
23
|
-
if (config && config.callbackURL) {
|
|
24
|
-
return config.callbackURL
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const db = getGlobalDB()
|
|
28
|
-
const publicConfig = await getScopedConfig(db, {
|
|
29
|
-
type: Configs.SETTINGS,
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
let callbackUrl = `/api/global/auth`
|
|
33
|
-
if (isMultiTenant()) {
|
|
34
|
-
callbackUrl += `/${getTenantId()}`
|
|
35
|
-
}
|
|
36
|
-
callbackUrl += `/${type}/callback`
|
|
37
|
-
|
|
38
|
-
return `${publicConfig.platformUrl}${callbackUrl}`
|
|
39
|
-
}
|
|
40
|
-
|
|
41
14
|
export const googleCallbackUrl = async (config: any) => {
|
|
42
|
-
return ssoCallbackUrl(config, "google")
|
|
15
|
+
return ssoCallbackUrl(getGlobalDB(), config, "google")
|
|
43
16
|
}
|
|
44
17
|
|
|
45
18
|
export const oidcCallbackUrl = async (config: any) => {
|
|
46
|
-
return ssoCallbackUrl(config, "oidc")
|
|
19
|
+
return ssoCallbackUrl(getGlobalDB(), config, "oidc")
|
|
47
20
|
}
|
|
48
21
|
|
|
49
22
|
async function authInternal(ctx: any, user: any, err = null, info = null) {
|
|
@@ -198,6 +171,8 @@ export const googlePreAuth = async (ctx: any, next: any) => {
|
|
|
198
171
|
|
|
199
172
|
return passport.authenticate(strategy, {
|
|
200
173
|
scope: ["profile", "email"],
|
|
174
|
+
accessType: "offline",
|
|
175
|
+
prompt: "consent",
|
|
201
176
|
})(ctx, next)
|
|
202
177
|
}
|
|
203
178
|
|
|
@@ -224,7 +199,7 @@ export const googleAuth = async (ctx: any, next: any) => {
|
|
|
224
199
|
)(ctx, next)
|
|
225
200
|
}
|
|
226
201
|
|
|
227
|
-
|
|
202
|
+
export const oidcStrategyFactory = async (ctx: any, configId: any) => {
|
|
228
203
|
const db = getGlobalDB()
|
|
229
204
|
const config = await core.db.getScopedConfig(db, {
|
|
230
205
|
type: Configs.OIDC,
|
|
@@ -234,7 +209,12 @@ async function oidcStrategyFactory(ctx: any, configId: any) {
|
|
|
234
209
|
const chosenConfig = config.configs.filter((c: any) => c.uuid === configId)[0]
|
|
235
210
|
let callbackUrl = await exports.oidcCallbackUrl(chosenConfig)
|
|
236
211
|
|
|
237
|
-
|
|
212
|
+
//Remote Config
|
|
213
|
+
const enrichedConfig = await oidc.fetchStrategyConfig(
|
|
214
|
+
chosenConfig,
|
|
215
|
+
callbackUrl
|
|
216
|
+
)
|
|
217
|
+
return oidc.strategyFactory(enrichedConfig, users.save)
|
|
238
218
|
}
|
|
239
219
|
|
|
240
220
|
/**
|
|
@@ -249,7 +229,7 @@ export const oidcPreAuth = async (ctx: any, next: any) => {
|
|
|
249
229
|
|
|
250
230
|
return passport.authenticate(strategy, {
|
|
251
231
|
// required 'openid' scope is added by oidc strategy factory
|
|
252
|
-
scope: ["profile", "email"],
|
|
232
|
+
scope: ["profile", "email", "offline_access"], //auth0 offline_access scope required for the refresh token behaviour.
|
|
253
233
|
})(ctx, next)
|
|
254
234
|
}
|
|
255
235
|
|
|
@@ -77,27 +77,30 @@ describe("/api/global/auth", () => {
|
|
|
77
77
|
describe("oidc", () => {
|
|
78
78
|
const auth = require("@budibase/backend-core/auth")
|
|
79
79
|
|
|
80
|
+
const passportSpy = jest.spyOn(auth.passport, "authenticate")
|
|
81
|
+
let oidcConf
|
|
82
|
+
let chosenConfig
|
|
83
|
+
let configId
|
|
84
|
+
|
|
80
85
|
// mock the oidc strategy implementation and return value
|
|
81
86
|
let strategyFactory = jest.fn()
|
|
82
87
|
let mockStrategyReturn = jest.fn()
|
|
88
|
+
let mockStrategyConfig = jest.fn()
|
|
89
|
+
auth.oidc.fetchStrategyConfig = mockStrategyConfig
|
|
90
|
+
|
|
83
91
|
strategyFactory.mockReturnValue(mockStrategyReturn)
|
|
84
92
|
auth.oidc.strategyFactory = strategyFactory
|
|
85
93
|
|
|
86
|
-
const passportSpy = jest.spyOn(auth.passport, "authenticate")
|
|
87
|
-
let oidcConf
|
|
88
|
-
let chosenConfig
|
|
89
|
-
let configId
|
|
90
|
-
|
|
91
94
|
beforeEach(async () => {
|
|
92
95
|
oidcConf = await config.saveOIDCConfig()
|
|
93
96
|
chosenConfig = oidcConf.config.configs[0]
|
|
94
97
|
configId = chosenConfig.uuid
|
|
98
|
+
mockStrategyConfig.mockReturnValue(chosenConfig)
|
|
95
99
|
})
|
|
96
100
|
|
|
97
101
|
afterEach(() => {
|
|
98
102
|
expect(strategyFactory).toBeCalledWith(
|
|
99
103
|
chosenConfig,
|
|
100
|
-
`http://localhost:10000/api/global/auth/${TENANT_ID}/oidc/callback`,
|
|
101
104
|
expect.any(Function)
|
|
102
105
|
)
|
|
103
106
|
})
|
|
@@ -107,7 +110,7 @@ describe("/api/global/auth", () => {
|
|
|
107
110
|
await request.get(`/api/global/auth/${TENANT_ID}/oidc/configs/${configId}`)
|
|
108
111
|
|
|
109
112
|
expect(passportSpy).toBeCalledWith(mockStrategyReturn, {
|
|
110
|
-
scope: ["profile", "email"]
|
|
113
|
+
scope: ["profile", "email", "offline_access"]
|
|
111
114
|
})
|
|
112
115
|
expect(passportSpy.mock.calls.length).toBe(1);
|
|
113
116
|
})
|