Skip to content

Commit

Permalink
refactor: restore param mutation/side-effects
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Apr 10, 2024
1 parent b9050fc commit dc1e4a8
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/org/authInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,26 +840,26 @@ export class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
let authConfig: AuthFields;

if (options) {
const clonedOptions = structuredClone(options);
options = structuredClone(options);

if (this.isTokenOptions(clonedOptions)) {
authConfig = clonedOptions;
if (this.isTokenOptions(options)) {
authConfig = options;
const userInfo = await this.retrieveUserInfo(
ensureString(clonedOptions.instanceUrl),
ensureString(clonedOptions.accessToken)
ensureString(options.instanceUrl),
ensureString(options.accessToken)
);
this.update({ username: userInfo?.username, orgId: userInfo?.organizationId });
} else {
if (this.options.parentUsername) {
const parentFields = await this.loadDecryptedAuthFromConfig(this.options.parentUsername);

clonedOptions.clientId = parentFields.clientId;
options.clientId = parentFields.clientId;

if (process.env.SFDX_CLIENT_SECRET) {
clonedOptions.clientSecret = process.env.SFDX_CLIENT_SECRET;
options.clientSecret = process.env.SFDX_CLIENT_SECRET;
} else {
// Grab whatever flow is defined
Object.assign(clonedOptions, {
Object.assign(options, {
clientSecret: parentFields.clientSecret,
privateKey: parentFields.privateKey ? pathResolve(parentFields.privateKey) : parentFields.privateKey,
});
Expand All @@ -868,20 +868,20 @@ export class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {

// jwt flow
// Support both sfdx and jsforce private key values
if (!clonedOptions.privateKey && clonedOptions.privateKeyFile) {
clonedOptions.privateKey = pathResolve(clonedOptions.privateKeyFile);
if (!options.privateKey && options.privateKeyFile) {
options.privateKey = pathResolve(options.privateKeyFile);
}

if (clonedOptions.privateKey) {
authConfig = await this.authJwt(clonedOptions);
} else if (!clonedOptions.authCode && clonedOptions.refreshToken) {
if (options.privateKey) {
authConfig = await this.authJwt(options);
} else if (!options.authCode && options.refreshToken) {
// refresh token flow (from sfdxUrl or OAuth refreshFn)
authConfig = await this.buildRefreshTokenConfig(clonedOptions);
authConfig = await this.buildRefreshTokenConfig(options);
} else if (this.options.oauth2 instanceof OAuth2) {
// authcode exchange / web auth flow
authConfig = await this.exchangeToken(clonedOptions, this.options.oauth2);
authConfig = await this.exchangeToken(options, this.options.oauth2);
} else {
authConfig = await this.exchangeToken(clonedOptions);
authConfig = await this.exchangeToken(options);
}
}

Expand Down

0 comments on commit dc1e4a8

Please sign in to comment.