Skip to content

clean up tokens on deauthorize #3872

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 2 commits into from
Apr 21, 2021
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
16 changes: 12 additions & 4 deletions components/server/src/user/user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,13 @@ export class UserService {
}

async checkTermsAccepted(user: User) {
const terms = this.termsProvider.getCurrent();
const accepted = await this.termsAcceptanceDb.getAcceptedRevision(user.id);
return !!accepted && (accepted.termsRevision === terms.revision);
// disabled terms acceptance check for now

return true;

// const terms = this.termsProvider.getCurrent();
// const accepted = await this.termsAcceptanceDb.getAcceptedRevision(user.id);
// return !!accepted && (accepted.termsRevision === terms.revision);
}

async isBlocked(params: CheckIsBlockedParams): Promise<boolean> {
Expand Down Expand Up @@ -274,7 +278,8 @@ export class UserService {

async deauthorize(user: User, authProviderId: string) {
const externalIdentities = user.identities.filter(i => i.authProviderId !== TokenService.GITPOD_AUTH_PROVIDER_ID);
if (!externalIdentities.some(i => i.authProviderId === authProviderId)) {
const identity = externalIdentities.find(i => i.authProviderId === authProviderId)
if (!identity) {
log.debug('Cannot deauthorize. Authorization not found.', { userId: user.id, authProviderId });
return;
}
Expand All @@ -283,6 +288,9 @@ export class UserService {
throw new Error("Cannot remove last provider authorization. Please delete account instead.");
}

// explicitly remove associated tokens
await this.userDb.deleteTokens(identity);

// effectively remove the provider authorization
user.identities = user.identities.filter(i => i.authProviderId !== authProviderId);
await this.userDb.storeUser(user);
Expand Down