-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
139 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ dist | |
package-lock.json | ||
.nyc_output | ||
coverage/ | ||
*.tsbuildinfo | ||
*.tsbuildinfo | ||
.vscode |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,38 @@ | ||
# authsignal-browser | ||
|
||
## API | ||
|
||
### challengeWithPopup | ||
|
||
You will need to add the following CSS to your application if using this method: | ||
|
||
```css | ||
.dialog-container, | ||
.dialog-overlay { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
} | ||
|
||
.dialog-container { | ||
z-index: 2; | ||
display: flex; | ||
} | ||
|
||
.dialog-container[aria-hidden="true"] { | ||
display: none; | ||
} | ||
|
||
.dialog-overlay { | ||
background-color: rgba(43, 46, 56, 0.9); | ||
} | ||
|
||
.dialog-content { | ||
margin: auto; | ||
z-index: 2; | ||
position: relative; | ||
background-color: white; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import A11yDialog from "a11y-dialog"; | ||
import {AuthsignalChallenge} from "./types"; | ||
|
||
const DIALOG_CONTAINER_ID = "authsignal-popup"; | ||
const DIALOG_CONTENT_ID = "authsignal-popup-content"; | ||
|
||
class PopupHandler { | ||
private popup: A11yDialog | null = null; | ||
|
||
constructor() { | ||
if (document.querySelector(`#${DIALOG_CONTAINER_ID}`)) { | ||
throw new Error("Multiple instances of Authsignal popup is not supported."); | ||
} | ||
|
||
this.create(); | ||
} | ||
|
||
create() { | ||
// Dialog container | ||
const container = document.createElement("div"); | ||
container.setAttribute("id", DIALOG_CONTAINER_ID); | ||
container.setAttribute("aria-hidden", "true"); | ||
container.setAttribute("class", "dialog-container"); | ||
|
||
// Dialog overlay | ||
const overlay = document.createElement("div"); | ||
overlay.setAttribute("class", "dialog-overlay"); | ||
overlay.setAttribute("data-a11y-dialog-hide", "true"); | ||
container.appendChild(overlay); | ||
|
||
// Dialog content | ||
const content = document.createElement("div"); | ||
content.setAttribute("class", "dialog-content"); | ||
content.setAttribute("id", DIALOG_CONTENT_ID); | ||
container.appendChild(content); | ||
|
||
document.body.appendChild(container); | ||
|
||
this.popup = new A11yDialog(container); | ||
this.popup.on("hide", this.destroy); | ||
} | ||
|
||
destroy() { | ||
const dialogEl = document.querySelector(`#${DIALOG_CONTAINER_ID}`); | ||
if (dialogEl) { | ||
document.body.removeChild(dialogEl); | ||
} | ||
} | ||
|
||
show({challengeUrl}: {challengeUrl: AuthsignalChallenge["challengeUrl"]}) { | ||
if (!this.popup) { | ||
throw new Error("Popup is not initialized"); | ||
} | ||
|
||
const iframe = document.createElement("iframe"); | ||
iframe.setAttribute("name", "authsignal"); | ||
iframe.setAttribute("title", "Authsignal multi-factor authentication challenge"); | ||
iframe.setAttribute("src", challengeUrl); | ||
iframe.setAttribute("width", "600"); | ||
iframe.setAttribute("height", "600"); | ||
iframe.setAttribute("frameborder", "0"); | ||
|
||
const dialogContent = document.querySelector(`#${DIALOG_CONTENT_ID}`); | ||
if (dialogContent) { | ||
dialogContent.appendChild(iframe); | ||
} | ||
|
||
this.popup.show(); | ||
} | ||
|
||
close() { | ||
if (!this.popup) { | ||
throw new Error("Popup is not initialized"); | ||
} | ||
|
||
this.popup.hide(); | ||
} | ||
} | ||
|
||
export {PopupHandler}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters