Allow auth provider bypass login form (#3025)

This commit is contained in:
Jason Hu 2019-03-27 20:54:10 -07:00 committed by Paulus Schoutsen
parent 44eaa3abad
commit 5080f4c2db

View File

@ -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);