From 5cb3e9c965269a7e442536fa1b6ba00add2c7153 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 23 Sep 2020 11:49:16 -0400 Subject: [PATCH] implement launchUri function (#177) --- src/cli/commands/login.command.ts | 8 +++++--- src/cli/services/cliPlatformUtils.service.ts | 10 +++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cli/commands/login.command.ts b/src/cli/commands/login.command.ts index 51aff1f1a6..26d401df8e 100644 --- a/src/cli/commands/login.command.ts +++ b/src/cli/commands/login.command.ts @@ -13,6 +13,7 @@ import { CryptoFunctionService } from '../../abstractions/cryptoFunction.service import { EnvironmentService } from '../../abstractions/environment.service'; import { I18nService } from '../../abstractions/i18n.service'; import { PasswordGenerationService } from '../../abstractions/passwordGeneration.service'; +import { PlatformUtilsService } from '../../abstractions/platformUtils.service'; import { Response } from '../models/response'; @@ -35,7 +36,8 @@ export class LoginCommand { constructor(protected authService: AuthService, protected apiService: ApiService, protected i18nService: I18nService, protected environmentService: EnvironmentService, protected passwordGenerationService: PasswordGenerationService, - protected cryptoFunctionService: CryptoFunctionService, clientId: string) { + protected cryptoFunctionService: CryptoFunctionService, protected platformUtilsService: PlatformUtilsService, + clientId: string) { this.clientId = clientId; } @@ -249,8 +251,8 @@ export class LoginCommand { for (let port = 8065; port <= 8070; port++) { try { this.ssoRedirectUri = 'http://localhost:' + port; - callbackServer.listen(port, async () => { - await open(webUrl + '/#/sso?clientId=' + this.clientId + + callbackServer.listen(port, () => { + this.platformUtilsService.launchUri(webUrl + '/#/sso?clientId=' + this.clientId + '&redirectUri=' + encodeURIComponent(this.ssoRedirectUri) + '&state=' + state + '&codeChallenge=' + codeChallenge); }); diff --git a/src/cli/services/cliPlatformUtils.service.ts b/src/cli/services/cliPlatformUtils.service.ts index 23a0aa01d0..f86adfeeac 100644 --- a/src/cli/services/cliPlatformUtils.service.ts +++ b/src/cli/services/cliPlatformUtils.service.ts @@ -1,8 +1,12 @@ +import * as child_process from 'child_process'; import { DeviceType } from '../../enums/deviceType'; import { PlatformUtilsService } from '../../abstractions/platformUtils.service'; +// tslint:disable-next-line +const open = require('open'); + export class CliPlatformUtilsService implements PlatformUtilsService { identityClientId: string; @@ -81,7 +85,11 @@ export class CliPlatformUtilsService implements PlatformUtilsService { } launchUri(uri: string, options?: any): void { - throw new Error('Not implemented.'); + if (process.platform === 'linux') { + child_process.spawnSync('xdg-open', [uri]); + } else { + open(uri); + } } saveFile(win: Window, blobData: any, blobOptions: any, fileName: string): void {