Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-db/src/auth-provider-entry-db.ts
2497 views
1
/**
2
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { AuthProviderEntry as AuthProviderEntry } from "@gitpod/gitpod-protocol";
8
import { createHash } from "crypto";
9
10
export const AuthProviderEntryDB = Symbol("AuthProviderEntryDB");
11
12
export interface AuthProviderEntryDB {
13
storeAuthProvider(ap: AuthProviderEntry, updateOAuthRevision: boolean): Promise<AuthProviderEntry>;
14
15
delete(ap: AuthProviderEntry): Promise<void>;
16
17
findAll(exceptOAuthRevisions?: string[]): Promise<AuthProviderEntry[]>;
18
/**
19
* `host`s contained in the result array are expected to be lower case.
20
*/
21
findAllHosts(): Promise<string[]>;
22
findByHost(host: string): Promise<AuthProviderEntry | undefined>;
23
findById(id: string): Promise<AuthProviderEntry | undefined>;
24
findByUserId(userId: string): Promise<AuthProviderEntry[]>;
25
findByOrgId(organizationId: string): Promise<AuthProviderEntry[]>;
26
}
27
28
export function hashOAuth(oauth: AuthProviderEntry["oauth"]): string {
29
return createHash("sha256").update(JSON.stringify(oauth)).digest("hex");
30
}
31
32