Skip to content

[server] Fix userService.deauthorize to disallow disconnecting the last auth provider #17022

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
merged 1 commit into from
Mar 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions components/server/src/user/user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ export class UserService {
}

async deauthorize(user: User, authProviderId: string) {
const builtInProviders = ["Public-GitLab", "Public-GitHub", "Public-Bitbucket"];
const externalIdentities = user.identities.filter(
(i) => i.authProviderId !== TokenService.GITPOD_AUTH_PROVIDER_ID,
);
Expand All @@ -476,10 +475,8 @@ export class UserService {
(i) => i !== identity && (!this.config.disableDynamicAuthProviderLogin || isBuiltin(i.authProviderId)),
);

if (
remainingLoginIdentities.length === 1 &&
!builtInProviders.includes(remainingLoginIdentities[0].authProviderId)
) {
// Disallow users to deregister the last builtin auth provider's from their user
if (remainingLoginIdentities.length === 0) {
throw new Error(
"Cannot remove last authentication provider for logging in to Gitpod. Please delete account if you want to leave.",
);
Expand Down