Skip to content

Commit

Permalink
fix(@schematics/update): process always-auth and _auth correctly, bet…
Browse files Browse the repository at this point in the history
…ter support for private repositories
  • Loading branch information
smnbbrv authored and hansl committed Sep 26, 2018
1 parent 8c4ddff commit b699ad2
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions packages/schematics/update/update/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ export function getNpmPackageJson(
getNpmConfigOption('_authToken', registryKey),
getNpmConfigOption('username', registryKey, true),
getNpmConfigOption('password', registryKey, true),
getNpmConfigOption('alwaysAuth', registryKey, true),
getNpmConfigOption('email', registryKey, true),
getNpmConfigOption('always-auth', registryKey, true),
).pipe(
toArray(),
concatMap(options => {
Expand All @@ -211,6 +212,7 @@ export function getNpmPackageJson(
authToken,
username,
password,
email,
alwaysAuth,
] = options;

Expand All @@ -222,17 +224,38 @@ export function getNpmPackageJson(
token?: string,
alwaysAuth?: boolean;
username?: string;
password?: string
password?: string;
email?: string;
} = {};

if (alwaysAuth !== undefined) {
auth.alwaysAuth = alwaysAuth === 'false' ? false : !!alwaysAuth;
}

if (email) {
auth.email = email;
}

if (authToken) {
auth.token = authToken;
} else if (token) {
auth.token = token;
try {
// attempt to parse "username:password" from base64 token
// to enable Artifactory / Nexus-like repositories support
const delimiter = ':';
const parsedToken = Buffer.from(token, 'base64').toString('ascii');
const [extractedUsername, ...passwordArr] = parsedToken.split(delimiter);
const extractedPassword = passwordArr.join(delimiter);

if (extractedUsername && extractedPassword) {
auth.username = extractedUsername;
auth.password = extractedPassword;
} else {
throw new Error('Unable to extract username and password from _auth token');
}
} catch (ex) {
auth.token = token;
}
} else if (username) {
auth.username = username;
auth.password = password;
Expand Down

0 comments on commit b699ad2

Please sign in to comment.