Skip to content
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

Fix error using refresh token #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ const args = require("minimist")(process.argv.slice(2), {
}
});

(async () => await run(args.client_id, args.tenant_id, args.ci, args.pbp))();
(async () => await run(args.client_id, args.ci, args.tenant_id, args.pbp))();
21 changes: 18 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { UserNpmConfig, ProjectNpmConfig } from "./npm-config";
import { UserYarnConfig, ProjectYarnConfig } from "./yarn-config";
import { resolve } from "path";
import * as fs from 'fs';
import * as https from 'https';
import * as path from 'path';

const AZDEVOPS_AUTH_TENANT_HEADER = "x-vss-resourcetenant";

const AZDEVOPS_RESOURCE_ID = "499b84ac-1321-427f-aa17-267ca6975798";
const AZDEVOPS_AUTH_CLIENT_ID = "f9d5fef7-a410-4582-bb27-68a319b1e5a1";
const AZDEVOPS_AUTH_CLIENT_ID = "872cd9fa-d31f-45e0-9eab-6e460a02d1f1";
const AZDEVOPS_AUTH_TENANT_ID = "common";

const CI_DEFAULT_ENV_VARIABLE_NAME = "TF_BUILD";
Expand All @@ -29,10 +32,20 @@ export function inCI(ciInfo: boolean | string) {
return true;
}

async function getRegistryTenantId(url: string): Promise<string | undefined> {
return new Promise((resolve, _reject) => {
https.get(url, (resp) => {
const tenantIdHeader = resp.headers[AZDEVOPS_AUTH_TENANT_HEADER];
const tenantId = Array.isArray(tenantIdHeader) ? tenantIdHeader[0] : tenantIdHeader;
resolve(tenantId);
});
});
}

async function run(
clientId = AZDEVOPS_AUTH_CLIENT_ID,
tenantId = AZDEVOPS_AUTH_TENANT_ID,
ciInfo: boolean | string,
tenantId?: string,
projectBasePath?: string
) {
if (inCI(ciInfo)) {
Expand All @@ -47,7 +60,9 @@ async function run(
for (const registry of getRegistries(userConfig, projectConfig)) {
console.log(chalk.green(`Found registry ${registry}`));

const issuer = await MsoIssuer.discover(tenantId);
const registryTenantId = tenantId ?? (await getRegistryTenantId(registry)) ?? AZDEVOPS_AUTH_TENANT_ID;

const issuer = await MsoIssuer.discover(registryTenantId);
const client = new issuer.Client(new MsoDeviceCodeClientMedata(clientId));

// Set timeout to 5s to workaround issue #18
Expand Down