1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

implement launchUri function (#177)

This commit is contained in:
Kyle Spearrin
2020-09-23 11:49:16 -04:00
committed by GitHub
parent 2ea1f8484f
commit 5cb3e9c965
2 changed files with 14 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ import { CryptoFunctionService } from '../../abstractions/cryptoFunction.service
import { EnvironmentService } from '../../abstractions/environment.service'; import { EnvironmentService } from '../../abstractions/environment.service';
import { I18nService } from '../../abstractions/i18n.service'; import { I18nService } from '../../abstractions/i18n.service';
import { PasswordGenerationService } from '../../abstractions/passwordGeneration.service'; import { PasswordGenerationService } from '../../abstractions/passwordGeneration.service';
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
import { Response } from '../models/response'; import { Response } from '../models/response';
@@ -35,7 +36,8 @@ export class LoginCommand {
constructor(protected authService: AuthService, protected apiService: ApiService, constructor(protected authService: AuthService, protected apiService: ApiService,
protected i18nService: I18nService, protected environmentService: EnvironmentService, protected i18nService: I18nService, protected environmentService: EnvironmentService,
protected passwordGenerationService: PasswordGenerationService, protected passwordGenerationService: PasswordGenerationService,
protected cryptoFunctionService: CryptoFunctionService, clientId: string) { protected cryptoFunctionService: CryptoFunctionService, protected platformUtilsService: PlatformUtilsService,
clientId: string) {
this.clientId = clientId; this.clientId = clientId;
} }
@@ -249,8 +251,8 @@ export class LoginCommand {
for (let port = 8065; port <= 8070; port++) { for (let port = 8065; port <= 8070; port++) {
try { try {
this.ssoRedirectUri = 'http://localhost:' + port; this.ssoRedirectUri = 'http://localhost:' + port;
callbackServer.listen(port, async () => { callbackServer.listen(port, () => {
await open(webUrl + '/#/sso?clientId=' + this.clientId + this.platformUtilsService.launchUri(webUrl + '/#/sso?clientId=' + this.clientId +
'&redirectUri=' + encodeURIComponent(this.ssoRedirectUri) + '&redirectUri=' + encodeURIComponent(this.ssoRedirectUri) +
'&state=' + state + '&codeChallenge=' + codeChallenge); '&state=' + state + '&codeChallenge=' + codeChallenge);
}); });

View File

@@ -1,8 +1,12 @@
import * as child_process from 'child_process';
import { DeviceType } from '../../enums/deviceType'; import { DeviceType } from '../../enums/deviceType';
import { PlatformUtilsService } from '../../abstractions/platformUtils.service'; import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
// tslint:disable-next-line
const open = require('open');
export class CliPlatformUtilsService implements PlatformUtilsService { export class CliPlatformUtilsService implements PlatformUtilsService {
identityClientId: string; identityClientId: string;
@@ -81,7 +85,11 @@ export class CliPlatformUtilsService implements PlatformUtilsService {
} }
launchUri(uri: string, options?: any): void { 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 { saveFile(win: Window, blobData: any, blobOptions: any, fileName: string): void {