-
Notifications
You must be signed in to change notification settings - Fork 2
feat(sso): sso support added #614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
4ef3df4
deps added, env updated
neSpecc 3ecdd48
bootstrap module
neSpecc 73fa3b9
models updated
neSpecc 025fdc1
update branch
neSpecc 223a946
tests for model and factory method added
neSpecc c7f9c29
rm redunant test cases
neSpecc 5892ea0
Update .nvmrc
neSpecc 1ca5fb8
Refactor SAML validation logic and add unit tests
neSpecc 77d55e9
rm try-catch from tests
neSpecc 61fea8e
Refactor SAML response validation to use node-saml
neSpecc 1369b2c
Implement SAML AuthnRequest generation and tests
neSpecc 0725454
SamlStateStore implemetation
neSpecc 1963a59
Implement SAML SSO controller and tests
neSpecc 76232df
Add SSO config support with admin-only GraphQL directive
neSpecc e9a6848
Add dynamic Node version and improve SAML SSO error handling
neSpecc 0ea60b7
Update build-and-push-docker-image.yml
neSpecc 1e9695b
Update build-and-push-docker-image.yml
neSpecc 6b3d58c
Update mongodb.ts
neSpecc 6cacb3a
Update controller.test.ts
neSpecc 19d03f6
Add public SSO workspace info query
neSpecc 65c22e3
Update workspace.js
neSpecc 154f59e
Enforce SSO login and refactor SSO config update
neSpecc c384e71
add logs to the sso controller
neSpecc fbb0afc
Shorten refresh token expiry for enforced SSO users
neSpecc de004e3
Create sso.test.ts
neSpecc 6e3d722
fixes for sso
neSpecc fc57f58
integration tests
neSpecc cf3c050
Bump version up to 1.2.33
github-actions[bot] 7190108
Update package.json
neSpecc 1080020
lint
neSpecc 73a89e6
fix tests
neSpecc de08345
Add pluggable SAML state store with Redis and memory support
neSpecc 26b9d2f
fix unti tests
neSpecc d95d526
fix integration tests
neSpecc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| v22.12.0 | ||
| v24.11.1 |
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import { defaultFieldResolver, GraphQLSchema } from 'graphql'; | ||
| import { mapSchema, MapperKind, getDirective } from '@graphql-tools/utils'; | ||
| import { ResolverContextWithUser, UnknownGraphQLResolverResult } from '../types/graphql'; | ||
| import { ForbiddenError, UserInputError } from 'apollo-server-express'; | ||
| import WorkspaceModel from '../models/workspace'; | ||
|
|
||
| /** | ||
| * Check if user is admin of workspace | ||
| * @param context - resolver context | ||
| * @param workspaceId - workspace id to check | ||
| * @returns true if user is admin, false otherwise | ||
| */ | ||
| async function isUserAdminOfWorkspace(context: ResolverContextWithUser, workspaceId: string): Promise<boolean> { | ||
| try { | ||
| const workspace = await context.factories.workspacesFactory.findById(workspaceId); | ||
|
|
||
| if (!workspace) { | ||
| return false; | ||
| } | ||
|
|
||
| const member = await workspace.getMemberInfo(context.user.id); | ||
|
|
||
| if (!member || WorkspaceModel.isPendingMember(member)) { | ||
| return false; | ||
| } | ||
|
|
||
| return member.isAdmin || false; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Defines directive for fields that are only defined for admins | ||
| * Returns null for non-admin users instead of throwing error | ||
| * | ||
| * Works with object fields where parent object has _id field (workspace id) | ||
| * | ||
| * Usage: | ||
| * type Workspace { | ||
| * sso: WorkspaceSsoConfig @definedOnlyForAdmins | ||
| * } | ||
| */ | ||
| export default function definedOnlyForAdminsDirective(directiveName = 'definedOnlyForAdmins') { | ||
| return { | ||
| definedOnlyForAdminsDirectiveTypeDefs: ` | ||
| """ | ||
| Field is only defined for admins. Returns null for non-admin users. | ||
| Works with object fields where parent object has _id field (workspace id). | ||
| """ | ||
| directive @${directiveName} on FIELD_DEFINITION | ||
| `, | ||
| definedOnlyForAdminsDirectiveTransformer: (schema: GraphQLSchema) => | ||
| mapSchema(schema, { | ||
| [MapperKind.OBJECT_FIELD]: (fieldConfig, fieldName, typeName) => { | ||
| const definedOnlyForAdminsDirective = getDirective(schema, fieldConfig, directiveName)?.[0]; | ||
|
|
||
| if (definedOnlyForAdminsDirective) { | ||
| const { | ||
| resolve = defaultFieldResolver, | ||
| } = fieldConfig; | ||
|
|
||
| /** | ||
| * New field resolver that checks admin rights | ||
| * @param resolverArgs - default GraphQL resolver args | ||
| */ | ||
| fieldConfig.resolve = async (...resolverArgs): UnknownGraphQLResolverResult => { | ||
| const [parent, , context] = resolverArgs; | ||
|
|
||
| /** | ||
| * Get workspace ID from parent object | ||
| * Parent should have _id field (workspace) | ||
| */ | ||
| if (!parent || !parent._id) { | ||
| return null; | ||
| } | ||
|
|
||
| const workspaceId = parent._id.toString(); | ||
|
|
||
| /** | ||
| * Check if user is admin | ||
| */ | ||
| const isAdmin = await isUserAdminOfWorkspace(context, workspaceId); | ||
|
|
||
| if (!isAdmin) { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Call original resolver | ||
| */ | ||
| return resolve(...resolverArgs); | ||
| }; | ||
| } | ||
|
|
||
| return fieldConfig; | ||
| }, | ||
| }), | ||
| }; | ||
| } | ||
|
|
||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.