diff --git a/src/auth/ha-auth-flow.js b/src/auth/ha-auth-flow.js index e07774c90b..ceb487a031 100644 --- a/src/auth/ha-auth-flow.js +++ b/src/auth/ha-auth-flow.js @@ -121,6 +121,12 @@ class HaAuthFlow extends localizeLiteMixin(PolymerElement) { const data = await response.json(); if (response.ok) { + // allow auth provider bypass the login form + if (data.type === "create_entry") { + this._redirect(data.result); + return; + } + this._updateStep(data); } else { this.setProperties({ @@ -138,6 +144,24 @@ class HaAuthFlow extends localizeLiteMixin(PolymerElement) { } } + _redirect(authCode) { + // OAuth 2: 3.1.2 we need to retain query component of a redirect URI + let url = this.redirectUri; + if (!url.includes("?")) { + url += "?"; + } else if (!url.endsWith("&")) { + url += "&"; + } + + url += `code=${encodeURIComponent(authCode)}`; + + if (this.oauth2State) { + url += `&state=${encodeURIComponent(this.oauth2State)}`; + } + + document.location = url; + } + _updateStep(step) { const props = { _step: step, @@ -229,21 +253,7 @@ class HaAuthFlow extends localizeLiteMixin(PolymerElement) { const newStep = await response.json(); if (newStep.type === "create_entry") { - // OAuth 2: 3.1.2 we need to retain query component of a redirect URI - let url = this.redirectUri; - if (!url.includes("?")) { - url += "?"; - } else if (!url.endsWith("&")) { - url += "&"; - } - - url += `code=${encodeURIComponent(newStep.result)}`; - - if (this.oauth2State) { - url += `&state=${encodeURIComponent(this.oauth2State)}`; - } - - document.location = url; + this._redirect(newStep.result); return; } this._updateStep(newStep);