Merged
Conversation
Contributor
Greptile SummaryThis PR adds a complete SCIM 2.0 user provisioning integration, covering a Prisma migration, a service layer, four route files ( All implementation details are correct:
The implementation is production-ready. Confidence Score: 5/5
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[IdP sends SCIM request] --> B[authenticateScim]
B --> C{scimEnabled AND<br/>token valid?}
C -- No --> D[401 Unauthorized]
C -- Yes --> E{HTTP Method + Path}
E --> F["POST /Users"]
F --> G[scimCreateUser]
G --> G1[user.create in DB]
G1 --> G2[writeAuditLog<br/>scim.user_created]
G2 --> G3[201 Created]
E --> H["PATCH /Users/:id"]
H --> I[scimPatchUser<br/>normalize op.op case]
I --> I1[user.update in DB]
I1 --> I2[writeAuditLog<br/>scim.user_patched]
I2 --> I3[200 OK]
E --> J["DELETE /Users/:id"]
J --> K[scimDeleteUser<br/>soft-lock only]
K --> K1[user.update<br/>lockedAt + lockedBy=SCIM]
K1 --> K2[writeAuditLog<br/>scim.user_deactivated]
K2 --> K3[204 No Content]
E --> L["PATCH /Groups/:id"]
L --> M[prisma transaction<br/>add or remove TeamMember]
M --> N[writeAuditLog<br/>scim.group_patched]
N --> O[200 OK]
E --> P["PUT /Groups/:id"]
P --> Q[prisma transaction<br/>deleteMany + create loop]
Q --> R[writeAuditLog<br/>scim.group_updated]
R --> S[200 OK]
Last reviewed commit: 46f1085 |
Add SCIM 2.0 protocol support for automated user lifecycle management from identity providers (Okta, Entra ID, etc.): - Prisma migration: scimExternalId on User, scimEnabled/scimBearerToken on SystemSettings - SCIM service layer with list/get/create/update/patch/delete user ops - API routes: /api/scim/v2/Users and /api/scim/v2/Groups with bearer token auth - Groups endpoints map SCIM Groups to VectorFlow Teams with member add/remove via PATCH - Settings router: enable/disable SCIM toggle, generate bearer token - Settings UI: SCIM tab with enable toggle, base URL display, token generation with copy-to-clipboard modal, and IdP setup instructions
- Create docs/public/operations/scim.md with setup guide, IdP-specific instructions (Okta, Entra ID, OneLogin), endpoint reference, filtering examples, security notes, and troubleshooting table - Update docs/public/operations/authentication.md with SCIM section linking to the new guide - Add SCIM page to docs/public/SUMMARY.md under Operations
- Use crypto.timingSafeEqual for bearer token comparison to prevent timing attacks - Extract shared authenticateScim into src/app/api/scim/v2/auth.ts - Wrap PUT /Groups/:id member replacement in Prisma transaction for atomicity - Add type validation on SCIM PATCH operation values before DB writes - Add audit logging to all SCIM mutations (user create, update, patch, deactivate)
When IdP asserts active:true, only clear locks that were SCIM-originated (lockedBy is "SCIM" or null). Admin-initiated locks are now preserved, preventing SCIM sync from silently re-activating accounts locked for security reasons. Applied to scimUpdateUser and both code paths in scimPatchUser.
Owner
Author
|
@greptile review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scimExternalIdto User andscimEnabled/scimBearerTokento SystemSettingslockedAtpattern (no hard deletes)/api/scim/v2/Usersand/api/scim/v2/Groupswith encrypted bearer token authTest plan
npx prisma migrate devto apply the migrationGET /api/scim/v2/Userswith valid/invalid bearer tokensPOST /api/scim/v2/Userswith SCIM JSON payloadPATCH /api/scim/v2/Users/:idwithactive: falseGET /api/scim/v2/Groupsand member management via PATCHnpx tsc --noEmit)