-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathdb.ts
181 lines (169 loc) · 6.71 KB
/
db.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/
import { OAuthClient, OAuthScope, OAuthToken } from "@jmondi/oauth2-server";
/**
* Currently (2021-05-15) we only support 1 client and a fixed set of scopes so hard-coding here is acceptable.
* This will change in time, in which case we can move to using the DB.
*/
export interface InMemory {
clients: { [id: string]: OAuthClient };
tokens: { [id: string]: OAuthToken };
scopes: { [id: string]: OAuthScope };
}
// Clients
const localAppClientID = "gplctl-1.0";
const localClient: OAuthClient = {
id: localAppClientID,
secret: `${localAppClientID}-secret`,
name: "Gitpod local control client",
// Set of valid redirect URIs
// NOTE: these need to be kept in sync with the port range in the local app
redirectUris: Array.from({ length: 10 }, (_, i) => "http://127.0.0.1:" + (63110 + i)),
allowedGrants: ["authorization_code"],
scopes: [
{ name: "function:getGitpodTokenScopes" },
{ name: "function:getWorkspace" },
{ name: "function:getWorkspaces" },
{ name: "function:listenForWorkspaceInstanceUpdates" },
{ name: "resource:default" },
],
};
const localCliClientID = "gitpod-cli";
const localCli: OAuthClient = {
id: localCliClientID,
secret: `${localCliClientID}-secret`,
name: "Gitpod CLI",
// Set of valid redirect URIs
// NOTE: these need to be kept in sync with the port range in the local app
redirectUris: Array.from({ length: 10 }, (_, i) => "http://127.0.0.1:" + (63110 + i)),
allowedGrants: ["authorization_code"],
scopes: [
{ name: "function:listenForWorkspaceInstanceUpdates" },
{ name: "function:getGitpodTokenScopes" },
{ name: "function:getLoggedInUser" },
{ name: "function:accessCodeSyncStorage" },
{ name: "function:getOwnerToken" },
{ name: "function:getWorkspace" },
{ name: "function:getWorkspaces" },
{ name: "function:getSSHPublicKeys" },
{ name: "function:startWorkspace" },
{ name: "function:stopWorkspace" },
{ name: "function:deleteWorkspace" },
{ name: "function:getTeam" },
{ name: "function:getTeams" },
{ name: "function:getTeamMembers" },
{ name: "function:getTeamProjects" },
{ name: "function:createWorkspace" },
{ name: "function:getToken" },
{ name: "function:getSupportedWorkspaceClasses" },
{ name: "function:getIDEOptions" },
{ name: "resource:default" },
],
};
const jetBrainsGateway: OAuthClient = {
id: "jetbrains-gateway-gitpod-plugin",
name: "JetBrains Gateway Gitpod Plugin",
// Set of valid redirect URIs
// NOTE: these need to be kept in sync with the port range in
// https://github.com/JetBrains/intellij-community/blob/8f07b83138bcb8a98a031e4508080c849a735644/platform/built-in-server/src/org/jetbrains/builtInWebServer/BuiltInServerOptions.java#L34
redirectUris: Array.from(
{ length: 20 },
(_, i) => `http://127.0.0.1:${63342 + i}/api/gitpod/oauth/authorization_code`,
),
allowedGrants: ["authorization_code"],
scopes: [
{ name: "function:getGitpodTokenScopes" },
{ name: "function:getIDEOptions" },
{ name: "function:getOwnerToken" },
{ name: "function:getWorkspace" },
{ name: "function:getWorkspaces" },
{ name: "function:listenForWorkspaceInstanceUpdates" },
{ name: "resource:default" },
],
};
function createVSCodeClient(protocol: string, displayName: string): OAuthClient {
return {
id: `${protocol}-gitpod`,
name: `${displayName}: Gitpod extension`,
redirectUris: [protocol + "://gitpod.gitpod-desktop/complete-gitpod-auth"],
allowedGrants: ["authorization_code"],
scopes: [
{ name: "function:getGitpodTokenScopes" },
{ name: "function:getLoggedInUser" },
{ name: "function:accessCodeSyncStorage" },
{ name: "function:getOwnerToken" },
{ name: "function:getWorkspace" },
{ name: "function:getWorkspaces" },
{ name: "function:getSSHPublicKeys" },
{ name: "function:sendHeartBeat" },
{ name: "function:startWorkspace" },
{ name: "function:stopWorkspace" },
{ name: "function:deleteWorkspace" },
{ name: "resource:default" },
],
};
}
const desktopClient: OAuthClient = {
id: "gitpod-desktop",
name: "Gitpod Desktop",
redirectUris: ["gitpod://complete-auth"],
allowedGrants: ["authorization_code"],
scopes: [
{ name: "function:getGitpodTokenScopes" },
{ name: "function:getLoggedInUser" },
{ name: "function:accessCodeSyncStorage" },
{ name: "function:getOwnerToken" },
{ name: "function:getWorkspace" },
{ name: "function:getWorkspaces" },
{ name: "function:getSSHPublicKeys" },
{ name: "function:startWorkspace" },
{ name: "function:stopWorkspace" },
{ name: "function:deleteWorkspace" },
{ name: "function:getTeams" },
{ name: "function:getTeamMembers" },
{ name: "function:getTeamProjects" },
{ name: "function:createWorkspace" },
{ name: "function:getToken" },
{ name: "function:getSupportedWorkspaceClasses" },
{ name: "function:getIDEOptions" },
{ name: "resource:default" },
],
};
const toolbox: OAuthClient = {
id: "toolbox-gateway-gitpod-plugin",
name: "JetBrains Toolbox Gitpod Plugin",
redirectUris: ["jetbrains://gateway/io.gitpod.toolbox.gateway/auth"],
allowedGrants: ["authorization_code"],
scopes: [
// We scope all so that it can work in papi like a PAT
{ name: "function:*" },
],
};
const vscode = createVSCodeClient("vscode", "VS Code");
const vscodeInsiders = createVSCodeClient("vscode-insiders", "VS Code Insiders");
const vscodium = createVSCodeClient("vscodium", "VSCodium");
const cursor = createVSCodeClient("cursor", "Cursor");
export const inMemoryDatabase: InMemory = {
clients: {
[localClient.id]: localClient,
[localCli.id]: localCli,
[jetBrainsGateway.id]: jetBrainsGateway,
[vscode.id]: vscode,
[vscodeInsiders.id]: vscodeInsiders,
[vscodium.id]: vscodium,
[cursor.id]: cursor,
[desktopClient.id]: desktopClient,
[toolbox.id]: toolbox,
},
tokens: {},
scopes: {},
};
for (const clientId in inMemoryDatabase.clients) {
const client = inMemoryDatabase.clients[clientId];
for (const scope of client.scopes) {
inMemoryDatabase.scopes[scope.name] = scope;
}
}