Skip to content

Commit

Permalink
Add Logging to SSO Process
Browse files Browse the repository at this point in the history
  • Loading branch information
justindbaur committed Jan 9, 2024
1 parent 4806380 commit e8a54a7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ import { setupExtensionDisconnectAction } from "../utils";
import ContentMessageHandler from "./content-message-handler";

(function (windowContext) {
// eslint-disable-next-line no-console -- In content script
console.debug("Initializing bitwardenContentMessageHandler");
if (!windowContext.bitwardenContentMessageHandler) {
windowContext.bitwardenContentMessageHandler = new ContentMessageHandler();
setupExtensionDisconnectAction(() => windowContext.bitwardenContentMessageHandler.destroy());
setupExtensionDisconnectAction(() => {
// eslint-disable-next-line no-console -- In content script
console.debug("Disconnecting content message handler.");
windowContext.bitwardenContentMessageHandler.destroy();
});

windowContext.bitwardenContentMessageHandler.init();
}
Expand Down
8 changes: 8 additions & 0 deletions apps/browser/src/autofill/content/content-message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ContentMessageHandler implements ContentMessageHandlerInterface {
* message listener.
*/
init() {
// eslint-disable-next-line no-console -- In content script
console.debug("Attaching message event listener.");
window.addEventListener("message", this.handleWindowMessage, false);
chrome.runtime.onMessage.addListener(this.handleExtensionMessage);
}
Expand All @@ -26,9 +28,13 @@ class ContentMessageHandler implements ContentMessageHandlerInterface {
* @param event - The message event.
*/
private handleWindowMessage = (event: MessageEvent) => {
// eslint-disable-next-line no-console -- In content script
console.debug("Handling window message");
const { source, data } = event;

if (source !== window || !data?.command) {
// eslint-disable-next-line no-console -- We are in a content script without our services
console.debug("Bad source or badly formatted message, skipping.");
return;
}

Expand All @@ -37,6 +43,8 @@ class ContentMessageHandler implements ContentMessageHandlerInterface {

if (command === "authResult") {
const { lastpass, code, state } = data;
// eslint-disable-next-line no-console -- In content script
console.debug("sending authResult message to chrome");
chrome.runtime.sendMessage({ command, code, state, lastpass, referrer });
}

Expand Down
1 change: 1 addition & 0 deletions apps/browser/src/background/runtime.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export default class RuntimeBackground {
}
break;
case "authResult": {
this.logService.debug("Handling authResult message");
const vaultUrl = this.environmentService.getWebVaultUrl();

if (msg.referrer == null || Utils.getHostname(vaultUrl) !== msg.referrer) {
Expand Down
19 changes: 11 additions & 8 deletions apps/browser/src/platform/popup/browser-popup-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,17 @@ class BrowserPopupUtils {
url: BrowserPopupUtils.buildPopoutUrl(extensionUrlPath, singleActionKey),
};

if (
(await BrowserPopupUtils.isSingleActionPopoutOpen(
singleActionKey,
popoutWindowOptions,
forceCloseExistingWindows,
)) &&
!forceCloseExistingWindows
) {
const isSingleActionPopoutOpen = await BrowserPopupUtils.isSingleActionPopoutOpen(
singleActionKey,
popoutWindowOptions,
forceCloseExistingWindows,
);
// eslint-disable-next-line no-console -- Laziness, static method that doesn't easily have access to LogService
console.debug("isSingleActionPopoutOpen", isSingleActionPopoutOpen);

if (isSingleActionPopoutOpen && !forceCloseExistingWindows) {
// eslint-disable-next-line no-console -- Laziness, static method that doesn't easily have access to LogService
console.debug("Skipping creation of popout window.");
return;
}

Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/connectors/sso.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getQsParam } from "./common";
import { getQsParam } from "./common";

require("./sso.scss");

Expand All @@ -24,6 +24,8 @@ document.addEventListener("DOMContentLoaded", () => {
});

function initiateBrowserSso(code: string, state: string, lastpass: boolean) {
// eslint-disable-next-line no-console -- In connector
console.debug("sending authResult message");
window.postMessage({ command: "authResult", code: code, state: state, lastpass: lastpass }, "*");
const handOffMessage = ("; " + document.cookie)
.split("; ssoHandOffMessage=")
Expand Down
1 change: 1 addition & 0 deletions libs/angular/src/auth/components/sso.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class SsoComponent {
async ngOnInit() {
// eslint-disable-next-line rxjs/no-async-subscribe
this.route.queryParams.pipe(first()).subscribe(async (qParams) => {
this.logService.info("Handling sso params");
if (qParams.code != null && qParams.state != null) {
const codeVerifier = await this.stateService.getSsoCodeVerifier();
const state = await this.stateService.getSsoState();
Expand Down

0 comments on commit e8a54a7

Please sign in to comment.