How to use the @salesforce/core.AuthInfo.create function in @salesforce/core

To help you get started, we’ve selected a few @salesforce/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ChuckJonas / ts-force / ts-force-gen / src / index.ts View on Github external
}

    if (args.sObjects || args.s) {
        config.sObjects = (args.sObjects || args.s).split(',');
    }

    if (config.auth.accessToken === undefined) {
        // if just username is set, load from sfdx
        if (config.auth.username !== undefined && config.auth.password === undefined) {
            let username = await Aliases.fetch(config.auth.username);
            if (username) {
                config.auth.username = username;
            }
            console.log(config.auth.username);
            let connection: Connection = await Connection.create({
                authInfo: await AuthInfo.create({ username: config.auth.username }
                )
            });
            let org = await Org.create({ connection });
            await org.refreshAuth();
            connection = org.getConnection();

            config.auth.accessToken = connection.accessToken;
            config.auth.instanceUrl = connection.instanceUrl;
        } else if (config.auth.username !== undefined && config.auth.password !== undefined) {

            // otherwise lets try username/password flow
            let pwConfig = new UsernamePasswordConfig(
                config.auth.clientId,
                config.auth.clientSecret,
                config.auth.oAuthHost,
                config.auth.username,
github wadewegner / sfdx-waw-plugin / src / commands / waw / auth / username / login.ts View on Github external
const conn = new jsforce.Connection({
      // you can change loginUrl to connect to sandbox or prerelease env.
      loginUrl: instanceUrl
    });

    await conn.login(username, password);

    const accessTokenOptions = {
      accessToken: conn.accessToken,
      instanceUrl: conn.instanceUrl,
      loginUrl: instanceUrl,
      orgId: getString(conn, 'userInfo.organizationId')
    };

    const auth = await AuthInfo.create({ username, accessTokenOptions });
    await auth.save();

    this.ux.log(`Authorized to ${username}`);

    return { username, accessTokenOptions };
  }
}
github forcedotcom / salesforcedx-vscode / packages / salesforcedx-vscode-core / src / util / authInfo.ts View on Github external
public static async isAScratchOrg(username: string): Promise {
    try {
      const authInfo = await AuthInfo.create({ username });
      const authInfoFields = authInfo.getFields();
      return Promise.resolve(
        typeof authInfoFields.devHubUsername !== 'undefined'
      );
    } catch (e) {
      throw e;
    }
  }
}