1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-19 02:51:14 +02:00
bitwarden-browser/apps/web/src/connectors/sso.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-03-16 17:44:31 +01:00
import { getQsParam } from "./common";
require("./sso.scss");
2022-02-24 12:10:07 +01:00
document.addEventListener("DOMContentLoaded", () => {
const code = getQsParam("code");
const state = getQsParam("state");
Modifications made to support Browser Extension SSO (#605) * Update feature/sso jslib 261a200 -> 2e823ea (#589) * [SSO] Reset master password (#580) * Initial commit reset master password (sso) * Reverted order of two factor/reset password conditional * Added necessary resetMasterPassword flag for potential entry into RMP flow * Complete Revamp: Reverted Register // Deleted reset-master-password // updated sso/(settings)change password to use use super class // Adjust routing/messages // Created (accounts) change-password * Updated button -> Set Master Password * Refactored change password sub classes to use new submit pattern * Cleaned import statements * Update jslib (7fa5178 -> fe167be) * Update jslib fe167be - >34632e5 * Fixed sso base class import * merge master * Fixed missing semicolon // updated jslib to whats in feature/sso * Fixed two factor formatting * Added new change password component to app module * Updated component selector * updating jslib 34632e5 -> 2e823ea * Fixed lint warning in two-factor component Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> * Update jslib to 101c568 (#594) * Support for dynamic clientid (#595) * support third party sso clients * jslib update * update jslib * Modifications made for Browser Extension SSO * Brought web specific ssocomponent into module * Removed sso complete transition * Fixed remaining merge issues * Removed un-needed block of code. * Moved processing to sso-connector. * Removed unused import * Fixed curly braces.. * Linter fixes * Aligned verbiage for process message handler * Lintr fixes * Firefox can't handle closing the window this way. * Update sso.ts Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
2020-08-20 21:30:22 +02:00
if (state != null && state.includes(":clientId=browser")) {
Modifications made to support Browser Extension SSO (#605) * Update feature/sso jslib 261a200 -> 2e823ea (#589) * [SSO] Reset master password (#580) * Initial commit reset master password (sso) * Reverted order of two factor/reset password conditional * Added necessary resetMasterPassword flag for potential entry into RMP flow * Complete Revamp: Reverted Register // Deleted reset-master-password // updated sso/(settings)change password to use use super class // Adjust routing/messages // Created (accounts) change-password * Updated button -> Set Master Password * Refactored change password sub classes to use new submit pattern * Cleaned import statements * Update jslib (7fa5178 -> fe167be) * Update jslib fe167be - >34632e5 * Fixed sso base class import * merge master * Fixed missing semicolon // updated jslib to whats in feature/sso * Fixed two factor formatting * Added new change password component to app module * Updated component selector * updating jslib 34632e5 -> 2e823ea * Fixed lint warning in two-factor component Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> * Update jslib to 101c568 (#594) * Support for dynamic clientid (#595) * support third party sso clients * jslib update * update jslib * Modifications made for Browser Extension SSO * Brought web specific ssocomponent into module * Removed sso complete transition * Fixed remaining merge issues * Removed un-needed block of code. * Moved processing to sso-connector. * Removed unused import * Fixed curly braces.. * Linter fixes * Aligned verbiage for process message handler * Lintr fixes * Firefox can't handle closing the window this way. * Update sso.ts Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
2020-08-20 21:30:22 +02:00
initiateBrowserSso(code, state);
2021-12-17 15:57:11 +01:00
} else {
Modifications made to support Browser Extension SSO (#605) * Update feature/sso jslib 261a200 -> 2e823ea (#589) * [SSO] Reset master password (#580) * Initial commit reset master password (sso) * Reverted order of two factor/reset password conditional * Added necessary resetMasterPassword flag for potential entry into RMP flow * Complete Revamp: Reverted Register // Deleted reset-master-password // updated sso/(settings)change password to use use super class // Adjust routing/messages // Created (accounts) change-password * Updated button -> Set Master Password * Refactored change password sub classes to use new submit pattern * Cleaned import statements * Update jslib (7fa5178 -> fe167be) * Update jslib fe167be - >34632e5 * Fixed sso base class import * merge master * Fixed missing semicolon // updated jslib to whats in feature/sso * Fixed two factor formatting * Added new change password component to app module * Updated component selector * updating jslib 34632e5 -> 2e823ea * Fixed lint warning in two-factor component Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> * Update jslib to 101c568 (#594) * Support for dynamic clientid (#595) * support third party sso clients * jslib update * update jslib * Modifications made for Browser Extension SSO * Brought web specific ssocomponent into module * Removed sso complete transition * Fixed remaining merge issues * Removed un-needed block of code. * Moved processing to sso-connector. * Removed unused import * Fixed curly braces.. * Linter fixes * Aligned verbiage for process message handler * Lintr fixes * Firefox can't handle closing the window this way. * Update sso.ts Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
2020-08-20 21:30:22 +02:00
window.location.href = window.location.origin + "/#/sso?code=" + code + "&state=" + state;
// Match any characters between "_returnUri='" and the next "'"
const returnUri = extractFromRegex(state, "(?<=_returnUri=')(.*)(?=')");
if (returnUri) {
window.location.href = window.location.origin + `/#${returnUri}`;
Modifications made to support Browser Extension SSO (#605) * Update feature/sso jslib 261a200 -> 2e823ea (#589) * [SSO] Reset master password (#580) * Initial commit reset master password (sso) * Reverted order of two factor/reset password conditional * Added necessary resetMasterPassword flag for potential entry into RMP flow * Complete Revamp: Reverted Register // Deleted reset-master-password // updated sso/(settings)change password to use use super class // Adjust routing/messages // Created (accounts) change-password * Updated button -> Set Master Password * Refactored change password sub classes to use new submit pattern * Cleaned import statements * Update jslib (7fa5178 -> fe167be) * Update jslib fe167be - >34632e5 * Fixed sso base class import * merge master * Fixed missing semicolon // updated jslib to whats in feature/sso * Fixed two factor formatting * Added new change password component to app module * Updated component selector * updating jslib 34632e5 -> 2e823ea * Fixed lint warning in two-factor component Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> * Update jslib to 101c568 (#594) * Support for dynamic clientid (#595) * support third party sso clients * jslib update * update jslib * Modifications made for Browser Extension SSO * Brought web specific ssocomponent into module * Removed sso complete transition * Fixed remaining merge issues * Removed un-needed block of code. * Moved processing to sso-connector. * Removed unused import * Fixed curly braces.. * Linter fixes * Aligned verbiage for process message handler * Lintr fixes * Firefox can't handle closing the window this way. * Update sso.ts Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
2020-08-20 21:30:22 +02:00
} else {
window.location.href = window.location.origin + "/#/sso?code=" + code + "&state=" + state;
Modifications made to support Browser Extension SSO (#605) * Update feature/sso jslib 261a200 -> 2e823ea (#589) * [SSO] Reset master password (#580) * Initial commit reset master password (sso) * Reverted order of two factor/reset password conditional * Added necessary resetMasterPassword flag for potential entry into RMP flow * Complete Revamp: Reverted Register // Deleted reset-master-password // updated sso/(settings)change password to use use super class // Adjust routing/messages // Created (accounts) change-password * Updated button -> Set Master Password * Refactored change password sub classes to use new submit pattern * Cleaned import statements * Update jslib (7fa5178 -> fe167be) * Update jslib fe167be - >34632e5 * Fixed sso base class import * merge master * Fixed missing semicolon // updated jslib to whats in feature/sso * Fixed two factor formatting * Added new change password component to app module * Updated component selector * updating jslib 34632e5 -> 2e823ea * Fixed lint warning in two-factor component Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> * Update jslib to 101c568 (#594) * Support for dynamic clientid (#595) * support third party sso clients * jslib update * update jslib * Modifications made for Browser Extension SSO * Brought web specific ssocomponent into module * Removed sso complete transition * Fixed remaining merge issues * Removed un-needed block of code. * Moved processing to sso-connector. * Removed unused import * Fixed curly braces.. * Linter fixes * Aligned verbiage for process message handler * Lintr fixes * Firefox can't handle closing the window this way. * Update sso.ts Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
2020-08-20 21:30:22 +02:00
}
2021-12-17 15:57:11 +01:00
}
});
Modifications made to support Browser Extension SSO (#605) * Update feature/sso jslib 261a200 -> 2e823ea (#589) * [SSO] Reset master password (#580) * Initial commit reset master password (sso) * Reverted order of two factor/reset password conditional * Added necessary resetMasterPassword flag for potential entry into RMP flow * Complete Revamp: Reverted Register // Deleted reset-master-password // updated sso/(settings)change password to use use super class // Adjust routing/messages // Created (accounts) change-password * Updated button -> Set Master Password * Refactored change password sub classes to use new submit pattern * Cleaned import statements * Update jslib (7fa5178 -> fe167be) * Update jslib fe167be - >34632e5 * Fixed sso base class import * merge master * Fixed missing semicolon // updated jslib to whats in feature/sso * Fixed two factor formatting * Added new change password component to app module * Updated component selector * updating jslib 34632e5 -> 2e823ea * Fixed lint warning in two-factor component Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> * Update jslib to 101c568 (#594) * Support for dynamic clientid (#595) * support third party sso clients * jslib update * update jslib * Modifications made for Browser Extension SSO * Brought web specific ssocomponent into module * Removed sso complete transition * Fixed remaining merge issues * Removed un-needed block of code. * Moved processing to sso-connector. * Removed unused import * Fixed curly braces.. * Linter fixes * Aligned verbiage for process message handler * Lintr fixes * Firefox can't handle closing the window this way. * Update sso.ts Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
2020-08-20 21:30:22 +02:00
function initiateBrowserSso(code: string, state: string) {
window.postMessage({ command: "authResult", code: code, state: state }, "*");
const handOffMessage = ("; " + document.cookie)
.split("; ssoHandOffMessage=")
.pop()
.split(";")
.shift();
document.cookie = "ssoHandOffMessage=;SameSite=strict;max-age=0";
2021-11-11 04:35:35 +01:00
const content = document.getElementById("content");
content.innerHTML = "";
2021-11-11 04:35:35 +01:00
const p = document.createElement("p");
p.innerText = handOffMessage;
content.appendChild(p);
Modifications made to support Browser Extension SSO (#605) * Update feature/sso jslib 261a200 -> 2e823ea (#589) * [SSO] Reset master password (#580) * Initial commit reset master password (sso) * Reverted order of two factor/reset password conditional * Added necessary resetMasterPassword flag for potential entry into RMP flow * Complete Revamp: Reverted Register // Deleted reset-master-password // updated sso/(settings)change password to use use super class // Adjust routing/messages // Created (accounts) change-password * Updated button -> Set Master Password * Refactored change password sub classes to use new submit pattern * Cleaned import statements * Update jslib (7fa5178 -> fe167be) * Update jslib fe167be - >34632e5 * Fixed sso base class import * merge master * Fixed missing semicolon // updated jslib to whats in feature/sso * Fixed two factor formatting * Added new change password component to app module * Updated component selector * updating jslib 34632e5 -> 2e823ea * Fixed lint warning in two-factor component Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> * Update jslib to 101c568 (#594) * Support for dynamic clientid (#595) * support third party sso clients * jslib update * update jslib * Modifications made for Browser Extension SSO * Brought web specific ssocomponent into module * Removed sso complete transition * Fixed remaining merge issues * Removed un-needed block of code. * Moved processing to sso-connector. * Removed unused import * Fixed curly braces.. * Linter fixes * Aligned verbiage for process message handler * Lintr fixes * Firefox can't handle closing the window this way. * Update sso.ts Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com> Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
2020-08-20 21:30:22 +02:00
}
function extractFromRegex(s: string, regexString: string) {
const regex = new RegExp(regexString);
const results = regex.exec(s);
if (!results) {
return null;
}
return results[0];
}