1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 02:33:46 +00:00

Modifications made to support browser sso

This commit is contained in:
Matt Smith
2020-08-14 12:48:50 -05:00
parent 09b7d7ec16
commit 2d56510f0e
10 changed files with 99 additions and 42 deletions

View File

@@ -32,25 +32,24 @@ export class HomeComponent {
special: false,
};
const state = await this.passwordGenerationService.generatePassword(passwordOptions);
const state = (await this.passwordGenerationService.generatePassword(passwordOptions)) + ':clientId=browser';
let codeVerifier = await this.passwordGenerationService.generatePassword(passwordOptions);
const codeVerifierHash = await this.cryptoFunctionService.hash(codeVerifier, 'sha256');
const codeChallenge = Utils.fromBufferToUrlB64(codeVerifierHash);
await this.storageService.save(ConstantsService.ssoCodeVerifierKey, codeVerifier);
await this.storageService.save(ConstantsService.ssoStateKey, state);
await this.storageService.save(ConstantsService.ssoClientId, ConstantsService.webClientId);
let url = this.environmentService.getWebVaultUrl();
if (url == null) {
url = 'https://vault.bitwarden.com';
}
const ssoRedirectUri = url + '/sso-connector.html';
const redirectUri = url + '/sso-connector.html';
// Launch browser
this.platformUtilsService.launchUri(url + '/#/sso?clientId=' + ConstantsService.webClientId +
'&redirectUri=' + encodeURIComponent(ssoRedirectUri) +
window.open(url + '/#/sso?clientId=browser' +
'&redirectUri=' + encodeURIComponent(redirectUri) +
'&state=' + state + '&codeChallenge=' + codeChallenge);
}
}

View File

@@ -2,7 +2,10 @@ import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from 'jslib/abstractions/auth.service';
import { CryptoFunctionService } from 'jslib/abstractions/cryptoFunction.service';
import { EnvironmentService } from 'jslib/abstractions/environment.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { StateService } from 'jslib/abstractions/state.service';
import { StorageService } from 'jslib/abstractions/storage.service';
@@ -16,10 +19,12 @@ import { LoginComponent as BaseLoginComponent } from 'jslib/angular/components/l
})
export class LoginComponent extends BaseLoginComponent {
constructor(authService: AuthService, router: Router,
platformUtilsService: PlatformUtilsService, i18nService: I18nService,
syncService: SyncService, storageService: StorageService,
stateService: StateService) {
super(authService, router, platformUtilsService, i18nService, storageService, stateService);
protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService,
protected stateService: StateService, protected environmentService: EnvironmentService,
protected passwordGenerationService: PasswordGenerationService,
protected cryptoFunctionService: CryptoFunctionService,
storageService: StorageService, syncService : SyncService) {
super(authService, router, platformUtilsService, i18nService, stateService, environmentService, passwordGenerationService, cryptoFunctionService, storageService);
super.onSuccessfulLogin = () => {
return syncService.fullSync(true);
};

View File

View File

@@ -0,0 +1,60 @@
import { Component } from '@angular/core';
import {
ActivatedRoute,
Router,
} from '@angular/router';
import { ApiService } from 'jslib/abstractions/api.service';
import { AuthService } from 'jslib/abstractions/auth.service';
import BrowserPlatformUtilsService from '../../services/browserPlatformUtils.service';
import { CryptoFunctionService } from 'jslib/abstractions/cryptoFunction.service';
import { ConstantsService } from 'jslib/services/constants.service';
import { EnvironmentService } from 'jslib/abstractions/environment.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { StateService } from 'jslib/abstractions/state.service';
import { StorageService } from 'jslib/abstractions/storage.service';
import { SyncService } from 'jslib/abstractions/sync.service';
import { SsoComponent as BaseSsoComponent } from 'jslib/angular/components/sso.component';
@Component({
selector: 'app-sso',
templateUrl: 'sso.component.html',
})
export class SsoComponent extends BaseSsoComponent {
constructor(authService: AuthService, router: Router,
i18nService: I18nService, route: ActivatedRoute,
storageService: StorageService, stateService: StateService,
platformUtilsService: PlatformUtilsService, apiService: ApiService,
cryptoFunctionService: CryptoFunctionService, passwordGenerationService: PasswordGenerationService,
syncService: SyncService, private browserPlatformUtilsService: BrowserPlatformUtilsService,
private environmentService: EnvironmentService ) {
super(authService, router, i18nService, route, storageService, stateService, platformUtilsService,
apiService, cryptoFunctionService, passwordGenerationService);
let url = this.environmentService.getWebVaultUrl();
if (url == null) {
url = 'https://vault.bitwarden.com';
}
this.redirectUri = url + '/sso-connector.html';
this.clientId = 'browser';
super.onSuccessfulLogin = () => {
var sidebarName : string = this.browserPlatformUtilsService.sidebarViewName();
var sidebarWindows = chrome.extension.getViews({ type: sidebarName });
if(sidebarWindows && sidebarWindows.length > 0) {
sidebarWindows[0].location.reload();
}
return syncService.fullSync(true);
};
super.onSuccessfulLoginTwoFactorNavigate = () => {
return router.navigate(['2fa']);
}
}
}

View File

@@ -18,6 +18,7 @@ import { LoginComponent } from './accounts/login.component';
import { RegisterComponent } from './accounts/register.component';
import { TwoFactorOptionsComponent } from './accounts/two-factor-options.component';
import { TwoFactorComponent } from './accounts/two-factor.component';
import { SsoComponent } from './accounts/sso.component';
import { PasswordGeneratorHistoryComponent } from './generator/password-generator-history.component';
import { PasswordGeneratorComponent } from './generator/password-generator.component';
import { PrivateModeComponent } from './private-mode.component';
@@ -79,6 +80,12 @@ const routes: Routes = [
canActivate: [LaunchGuardService],
data: { state: '2fa-options' },
},
{
path: 'sso',
component: SsoComponent,
canActivate: [LaunchGuardService],
data: { state: 'sso' },
},
{
path: 'register',
component: RegisterComponent,

View File

@@ -23,6 +23,7 @@ import { LoginComponent } from './accounts/login.component';
import { RegisterComponent } from './accounts/register.component';
import { TwoFactorOptionsComponent } from './accounts/two-factor-options.component';
import { TwoFactorComponent } from './accounts/two-factor.component';
import { SsoComponent } from './accounts/sso.component';
import { AppComponent } from './app.component';
import { PasswordGeneratorHistoryComponent } from './generator/password-generator-history.component';
import { PasswordGeneratorComponent } from './generator/password-generator.component';
@@ -206,6 +207,7 @@ registerLocaleData(localeZhTw, 'zh-TW');
TrueFalseValueDirective,
TwoFactorOptionsComponent,
TwoFactorComponent,
SsoComponent,
ViewComponent,
],
entryComponents: [],

View File

@@ -78,4 +78,12 @@ export class PopupUtilsService {
// Safari can't open popup in full page tab :(
}
}
ProcessSso(code: string, state: string)
{
// Redirect to SSO token validation.
chrome.tabs.create({
url: 'popup/index.html?uilocation=popout#/sso?code=' + code + '&state=' + state
});
}
}