From 42361d17b52845935688f170488b2bb16a13d733 Mon Sep 17 00:00:00 2001 From: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Date: Tue, 7 Jul 2020 13:32:22 -0500 Subject: [PATCH] [Enterprise] Added button to launch portal (#570) * initial commit * Added Enterprise button and used new business portal bool * Reverting services module local changes * Formatted some new lines --- package-lock.json | 2 +- .../organization-layout.component.html | 85 +++++++++++-------- .../layouts/organization-layout.component.ts | 27 +++++- 3 files changed, 72 insertions(+), 42 deletions(-) diff --git a/package-lock.json b/package-lock.json index f22bbb576c..c15d6b496b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3501,7 +3501,7 @@ } }, "duo_web_sdk": { - "version": "git+https://github.com/duosecurity/duo_web_sdk.git#410a9186cc34663c4913b17d6528067cd3331f1d", + "version": "git+https://github.com/duosecurity/duo_web_sdk.git#4c5df7a4001b8b03e2d7130d9096b697c4032e77", "from": "git+https://github.com/duosecurity/duo_web_sdk.git" }, "duplexify": { diff --git a/src/app/layouts/organization-layout.component.html b/src/app/layouts/organization-layout.component.html index 3ca204fe71..6280f875d9 100644 --- a/src/app/layouts/organization-layout.component.html +++ b/src/app/layouts/organization-layout.component.html @@ -1,45 +1,56 @@
-
-
- -
- {{organization.name}} - {{'organization' | i18n}} -
-
-
- - {{'organizationIsDisabled' | i18n}} +
+
+
+ +
+ {{organization.name}} + {{'organization' | i18n}} +
+
+
+ + {{'organizationIsDisabled' | i18n}} +
+ +
+
+
-
diff --git a/src/app/layouts/organization-layout.component.ts b/src/app/layouts/organization-layout.component.ts index 67269d9e25..9410d39421 100644 --- a/src/app/layouts/organization-layout.component.ts +++ b/src/app/layouts/organization-layout.component.ts @@ -4,11 +4,14 @@ import { OnDestroy, OnInit, } from '@angular/core'; + import { ActivatedRoute } from '@angular/router'; import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; +import { ApiService } from 'jslib/abstractions/api.service'; import { EnvironmentService } from 'jslib/abstractions/environment.service'; +import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { UserService } from 'jslib/abstractions/user.service'; import { Organization } from 'jslib/models/domain/organization'; @@ -21,13 +24,14 @@ const BroadcasterSubscriptionId = 'OrganizationLayoutComponent'; }) export class OrganizationLayoutComponent implements OnInit, OnDestroy { organization: Organization; - + enterpriseTokenPromise: Promise; private organizationId: string; private enterpriseUrl: string; constructor(private route: ActivatedRoute, private userService: UserService, - private broadcasterService: BroadcasterService, private environmentService: EnvironmentService, - private ngZone: NgZone) { } + private broadcasterService: BroadcasterService, private ngZone: NgZone, + private apiService: ApiService, private platformUtilsService: PlatformUtilsService, + private environmentService: EnvironmentService) { } ngOnInit() { this.enterpriseUrl = 'https://enterprise.bitwarden.com'; @@ -42,7 +46,6 @@ export class OrganizationLayoutComponent implements OnInit, OnDestroy { this.organizationId = params.organizationId; await this.load(); }); - this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => { this.ngZone.run(async () => { switch (message.command) { @@ -61,4 +64,20 @@ export class OrganizationLayoutComponent implements OnInit, OnDestroy { async load() { this.organization = await this.userService.getOrganization(this.organizationId); } + + async goToEnterprisePortal() { + if (this.enterpriseTokenPromise != null) { + return; + } + try { + this.enterpriseTokenPromise = this.apiService.getEnterprisePortalSignInToken(); + const token = await this.enterpriseTokenPromise; + if (token != null) { + const userId = await this.userService.getUserId(); + this.platformUtilsService.launchUri(this.enterpriseUrl + '/login?userId=' + userId + + '&token=' + (window as any).encodeURIComponent(token) + '&organizationId=' + this.organization.id); + } + } catch { } + this.enterpriseTokenPromise = null; + } }