Skip to content

[server] add vscode(-insiders) ouath2 clients #5793

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
31 changes: 27 additions & 4 deletions components/server/src/oauth-server/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface InMemory {
}

// Scopes
const scopes: OAuthScope[] = [
const localAppScopes: OAuthScope[] = [
{ name: "function:getGitpodTokenScopes" },
{ name: "function:getWorkspace" },
{ name: "function:getWorkspaces" },
Expand All @@ -35,16 +35,39 @@ const localClient: OAuthClient = {
// 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,
scopes: localAppScopes,
}

function createVSCodeClient(protocol: 'vscode' | 'vscode-insiders'): OAuthClient {
return {
id: protocol + '-' + 'gitpod',
name: `VS Code${protocol === 'vscode-insiders' ? ' Insiders' : ''}: Gitpod`,
redirectUris: [protocol + '://gitpod.gitpod-desktop/complete-gitpod-auth'],
allowedGrants: ['authorization_code'],
scopes: [
{ name: "function:getGitpodTokenScopes" },
{ name: "function:getLoggedInUser" },
{ name: "function:accessCodeSyncStorage" },
{ name: "resource:default" }
],
}
}

const vscode = createVSCodeClient('vscode');
const vscodeInsiders = createVSCodeClient('vscode-insiders');

export const inMemoryDatabase: InMemory = {
clients: {
[localClient.id]: localClient,
[vscode.id]: vscode,
[vscodeInsiders.id]: vscodeInsiders
},
tokens: {},
scopes: {},
};
for (const scope of scopes) {
inMemoryDatabase.scopes[scope.name] = scope;
for (const clientId in inMemoryDatabase.clients) {
const client = inMemoryDatabase.clients[clientId];
for (const scope of client.scopes) {
inMemoryDatabase.scopes[scope.name] = scope;
}
}
7 changes: 5 additions & 2 deletions components/server/src/oauth-server/oauth-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { log } from '@gitpod/gitpod-protocol/lib/util/logging';
import { OAuthException, OAuthRequest, OAuthResponse } from "@jmondi/oauth2-server";
import * as express from 'express';
import { inject, injectable } from "inversify";
import { URL } from 'url';
import { Config } from '../config';
import { clientRepository, createAuthorizationServer } from './oauth-authorization-server';

Expand Down Expand Up @@ -50,8 +51,10 @@ export class OAuthController {
}

// Let the local app know they rejected the approval
const rt = req.query.redirect_uri;
if (!rt || !rt.startsWith("http://127.0.0.1:")) {
const rt: string = req.query.redirect_uri;
const redirectURLObject = new URL(rt);

if (!rt || !rt.startsWith("http://127.0.0.1:") || !(['vscode:', 'vscode-insiders:'].includes(redirectURLObject.protocol) && redirectURLObject.pathname !== '//gitpod.gitpod-desktop/complete-gitpod-auth')) {
log.error(`/oauth/authorize: invalid returnTo URL: "${rt}"`)
res.sendStatus(400);
return false;
Expand Down