diff --git a/src/commands/auth/device/login.ts b/src/commands/auth/device/login.ts index a72b3076..76cd5eed 100644 --- a/src/commands/auth/device/login.ts +++ b/src/commands/auth/device/login.ts @@ -9,6 +9,7 @@ import * as os from 'os'; import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command'; import { AuthFields, DeviceOauthService, Messages, OAuth2Options } from '@salesforce/core'; +import { get, Optional } from '@salesforce/ts-types'; import { Prompts } from '../../../prompts'; import { Common } from '../../../common'; @@ -52,7 +53,7 @@ export default class Login extends SfdxCommand { if (await Prompts.shouldExitCommand(this.ux, this.flags.noprompt)) return {}; const oauthConfig: OAuth2Options = { - loginUrl: this.flags.instanceurl, + loginUrl: get(this.flags.instanceurl, 'href', null) as Optional, clientId: this.flags.clientid, }; diff --git a/test/commands/auth/device/login.test.ts b/test/commands/auth/device/login.test.ts index 5e0677c4..9210b9ee 100644 --- a/test/commands/auth/device/login.test.ts +++ b/test/commands/auth/device/login.test.ts @@ -92,6 +92,18 @@ describe('auth:device:login', async () => { expect(response.result.username).to.equal(testData.username); }); + test + .do(async () => prepareStubs()) + .stdout() + .command(['auth:device:login', '-r', 'https://login.salesforce.com', '--json']) + .it('should return auth fields with instance url', (ctx) => { + const [action, response] = parseJsonResponse(ctx.stdout); + expect(action).to.deep.equal(mockAction); + expect(response.status).to.equal(0); + expect(response.result).to.deep.equal(authFields); + expect(response.result.username).to.equal(testData.username); + }); + test .do(async () => prepareStubs()) .stdout()