-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to update the mappers of an IDP (#1222)
- Loading branch information
1 parent
7c3781f
commit 00c7b2e
Showing
14 changed files
with
4,401 additions
and
3,533 deletions.
There are no files selected for viewing
7,041 changes: 3,598 additions & 3,443 deletions
7,041
connect-go/gen/proto/wg/cosmo/platform/v1/platform.pb.go
Large diffs are not rendered by default.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
connect-go/gen/proto/wg/cosmo/platform/v1/platformv1connect/platform.connect.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 17 additions & 1 deletion
18
connect/src/wg/cosmo/platform/v1/platform-PlatformService_connectquery.ts
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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,71 @@ | ||
import { PlainMessage } from '@bufbuild/protobuf'; | ||
import { HandlerContext } from '@connectrpc/connect'; | ||
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb'; | ||
import { | ||
GetOIDCProviderRequest, | ||
GetOIDCProviderResponse, | ||
UpdateIDPMappersRequest, | ||
UpdateIDPMappersResponse, | ||
} from '@wundergraph/cosmo-connect/dist/platform/v1/platform_pb'; | ||
import { OidcRepository } from '../../repositories/OidcRepository.js'; | ||
import type { RouterOptions } from '../../routes.js'; | ||
import { enrichLogger, getLogger, handleError } from '../../util.js'; | ||
import OidcProvider from '../../services/OidcProvider.js'; | ||
|
||
export function updateIDPMappers( | ||
opts: RouterOptions, | ||
req: UpdateIDPMappersRequest, | ||
ctx: HandlerContext, | ||
): Promise<PlainMessage<UpdateIDPMappersResponse>> { | ||
let logger = getLogger(ctx, opts.logger); | ||
|
||
return handleError<PlainMessage<UpdateIDPMappersResponse>>(ctx, logger, async () => { | ||
const authContext = await opts.authenticator.authenticate(ctx.requestHeader); | ||
logger = enrichLogger(ctx, logger, authContext); | ||
|
||
if (!authContext.isAdmin) { | ||
return { | ||
response: { | ||
code: EnumStatusCode.ERR, | ||
details: `The user doesnt have the permissions to perform this operation`, | ||
}, | ||
}; | ||
} | ||
|
||
const oidcProvider = new OidcProvider(); | ||
const oidcRepo = new OidcRepository(opts.db); | ||
|
||
await opts.keycloakClient.authenticateClient(); | ||
|
||
const provider = await oidcRepo.getOidcProvider({ organizationId: authContext.organizationId }); | ||
if (!provider) { | ||
return { | ||
response: { | ||
code: EnumStatusCode.ERR_NOT_FOUND, | ||
details: `OIDC Provider not found`, | ||
}, | ||
}; | ||
} | ||
|
||
await oidcProvider.deleteIDPMappers({ | ||
alias: provider.alias, | ||
kcClient: opts.keycloakClient, | ||
kcRealm: opts.keycloakRealm, | ||
}); | ||
|
||
await oidcProvider.addIDPMappers({ | ||
kcClient: opts.keycloakClient, | ||
kcRealm: opts.keycloakRealm, | ||
mappers: req.mappers, | ||
organizationSlug: authContext.organizationSlug, | ||
endpoint: provider.endpoint, | ||
alias: provider.alias, | ||
}); | ||
|
||
return { | ||
response: { | ||
code: EnumStatusCode.OK, | ||
}, | ||
}; | ||
}); | ||
} |
This file contains 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.