Skip to content

Commit a0ae008

Browse files
authored
Merge pull request #3533 from OpenNeuroOrg/worker-scope-tokens
feat(server): Allow worker scopes for tokens
2 parents 093bcc8 + 596b6f7 commit a0ae008

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

packages/openneuro-server/src/graphql/permissions.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,18 @@ export const checkDatasetWrite = async (
138138
// Quick path for anonymous writes
139139
throw new Error(state.errorMessage)
140140
}
141-
if (userId && !(userInfo.email)) {
142-
throw new Error("Connect an email to make contributions to OpenNeuro.")
143-
}
144141
if (userId && userInfo.admin) {
145142
// Always allow site admins
146143
return true
147144
}
145+
// Allow worker scoped tokens to make admin actions on specific datasets
146+
if (userId && userInfo?.worker && datasetId === userInfo?.dataset) {
147+
return true
148+
}
149+
if (userId && !(userInfo.email)) {
150+
throw new Error("Connect an email to make contributions to OpenNeuro.")
151+
}
152+
// Finally check the permissions model if other checks have not returned
148153
const permission = await Permission.findOne({ datasetId, userId }).exec()
149154
if (checkPermissionLevel(permission, state)) {
150155
return true

packages/openneuro-server/src/libs/authentication/passport.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ export const setupPassportAuth = () => {
120120
(jwt, done) => {
121121
if (jwt.scopes?.includes("dataset:indexing")) {
122122
done(null, { admin: false, blocked: false, indexer: true })
123+
} else if (jwt.scopes?.includes("dataset:worker")) {
124+
done(null, {
125+
id: jwt.sub,
126+
admin: false,
127+
blocked: false,
128+
worker: true,
129+
dataset: jwt.dataset,
130+
})
123131
} else if (jwt.scopes?.includes("dataset:reviewer")) {
124132
done(null, {
125133
admin: false,

0 commit comments

Comments
 (0)