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

Added support for Azure DevOps server published with Azure Application Proxy #40

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
5 changes: 3 additions & 2 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ const args = require("minimist")(process.argv.slice(2), {
cid: "client_id",
tid: "tenant_id",
ci: "continuous_integration_variable",
pbp: "project_base_path"
pbp: "project_base_path",
resid: "resource_id"
}
});

(async () => await run(args.client_id, args.tenant_id, args.ci, args.pbp))();
(async () => await run(args.client_id, args.tenant_id, args.ci, args.pbp, args.resid))();
13 changes: 7 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ async function run(
clientId = AZDEVOPS_AUTH_CLIENT_ID,
tenantId = AZDEVOPS_AUTH_TENANT_ID,
ciInfo: boolean | string,
projectBasePath?: string
projectBasePath?: string,
resourceId = AZDEVOPS_RESOURCE_ID
) {
if (inCI(ciInfo)) {
return;
Expand Down Expand Up @@ -67,18 +68,18 @@ async function run(
switch (exception.error) {
case "invalid_grant":
console.log(chalk.yellow("Refresh token is invalid or expired."));
tokenSet = await startDeviceCodeFlow(client);
tokenSet = await startDeviceCodeFlow(client, resourceId);
break;
case "interaction_required":
console.log(chalk.yellow("Interaction required."));
tokenSet = await startDeviceCodeFlow(client);
tokenSet = await startDeviceCodeFlow(client, resourceId);
break;
default:
throw exception;
}
}
} else {
tokenSet = await startDeviceCodeFlow(client);
tokenSet = await startDeviceCodeFlow(client, resourceId);
}

// Update user npm config with tokens
Expand All @@ -91,12 +92,12 @@ async function run(
}
}

async function startDeviceCodeFlow(client: Client) {
async function startDeviceCodeFlow(client: Client, resourceId: string) {
console.log(chalk.green("Launching device code authentication..."));

// Make sure to include 'offline_access' scope to receive refresh token.
const handle = await client.deviceAuthorization({
scope: `${AZDEVOPS_RESOURCE_ID}/.default offline_access`
scope: `${resourceId}/.default offline_access`
});

console.log(
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "azure-devops-npm-auth",
"version": "1.1.1",
"version": "1.2.1",
"description": "Authentication utility for private NPM registries hosted in Azure DevOps.",
"keywords": [
"azure",
"devops",
"azure-devops-server",
"npm",
"authentication",
"artifact",
Expand Down