-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support external step for Authentication providers in login flow
- Loading branch information
1 parent
7750299
commit 5b56570
Showing
3 changed files
with
100 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type { CSSResultGroup, TemplateResult } from "lit"; | ||
import { css, html } from "lit"; | ||
import { customElement, property } from "lit/decorators"; | ||
import type { DataEntryFlowStepExternal } from "../../data/data_entry_flow"; | ||
import { fireEvent } from "../common/dom/fire_event"; | ||
import type { LocalizeFunc } from "../common/translations/localize"; | ||
import { HaForm } from "../components/ha-form/ha-form"; | ||
|
||
@customElement("ha-auth-external") | ||
export class HaAuthExternal extends HaForm { | ||
@property({ attribute: false }) public localize?: LocalizeFunc; | ||
|
||
@property({ attribute: false }) public stepTitle?: string; | ||
|
||
@property({ attribute: false }) public step!: DataEntryFlowStepExternal; | ||
|
||
protected render(): TemplateResult { | ||
return html` | ||
<h2>${this.stepTitle}</h2> | ||
<div class="content"> | ||
${this.localize("ui.panel.page-authorize.external.description")} | ||
<div class="open-button"> | ||
<a href=${this.step.url} target="_blank" rel="opener"> | ||
<mwc-button raised> | ||
${this.localize("ui.panel.page-authorize.external.open_site")} | ||
</mwc-button> | ||
</a> | ||
</div> | ||
</div> | ||
`; | ||
} | ||
|
||
protected firstUpdated(changedProps) { | ||
super.firstUpdated(changedProps); | ||
window.open(this.step.url); | ||
window.addEventListener("message", async (message: MessageEvent) => { | ||
if (message.data.type === "externalCallback") { | ||
fireEvent(this, "step-finished"); | ||
} | ||
}); | ||
} | ||
|
||
static get styles(): CSSResultGroup { | ||
return [ | ||
css` | ||
.open-button { | ||
text-align: center; | ||
padding: 24px 0; | ||
} | ||
.open-button a { | ||
text-decoration: none; | ||
} | ||
`, | ||
]; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"ha-auth-external": HaAuthExternal; | ||
} | ||
interface HASSDomEvents { | ||
"step-finished": undefined; | ||
} | ||
} |
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