Skip to content

Commit

Permalink
set origin header
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuss committed Dec 7, 2023
1 parent 23a3d6f commit 1607bf8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@
"qrcode-svg": "^1.1.0",
"which": "^4.0.0"
}
}
}
13 changes: 12 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import packageJson from "../package.json";
import os from "os";
import { Configuration } from "./config";

type Headers = { "user-agent": string; "x-2fa-code"?: string };
type Headers = { "user-agent": string; "x-2fa-code"?: string; origin?: string };

const USER_AGENT = `${packageJson.name}/${
packageJson.version
Expand Down Expand Up @@ -113,6 +113,12 @@ export class ApiFactory {
headers["x-2fa-code"] = `${twoFactorCode}`;
}

// Origin header for Codespaces Identity
const repository = this.configuration.github.repository;
if (repository) {
headers["origin"] = repository;
}

const configuration = new IDPConfiguration({
accessToken: accessToken || (await this.getAccessToken(twoFactorCode)),
baseOptions: {
Expand All @@ -137,6 +143,11 @@ export class ApiFactory {
headers["x-2fa-code"] = `${twoFactorCode}`;
}

const repository = this.configuration.github.repository;
if (repository) {
headers["origin"] = repository;
}

const configuration = new IDPConfiguration({
accessToken: accessToken || (await this.getAccessToken(twoFactorCode)),
baseOptions: {
Expand Down
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class GitHubConfiguration {
const fromEnv = process.env.GITHUB_TOKEN;
return fromConfig || fromEnv;
}

get repository(): string | undefined {
// TODO: alternate read from /workspaces/.codespaces/shared/.env
const fromEnv = process.env.GITHUB_REPOSITORY;
return fromEnv;
}
}

class AssumeAwsProfileConfiguration {
Expand Down

0 comments on commit 1607bf8

Please sign in to comment.