allow 'same-origin' credentials for fetch() (#1530)

This commit is contained in:
Alexei Chetroi 2018-08-02 08:11:53 -04:00 committed by Paulus Schoutsen
parent db310646b7
commit cc652a9476
6 changed files with 7 additions and 2 deletions

View File

@ -72,6 +72,7 @@ class HaAuthFlow extends EventsMixin(PolymerElement) {
fetch('/auth/login_flow', { fetch('/auth/login_flow', {
method: 'POST', method: 'POST',
credentials: 'same-origin',
body: JSON.stringify({ body: JSON.stringify({
client_id: this.clientId, client_id: this.clientId,
handler: [this.authProvider.type, this.authProvider.id], handler: [this.authProvider.type, this.authProvider.id],
@ -111,6 +112,7 @@ class HaAuthFlow extends EventsMixin(PolymerElement) {
fetch(`/auth/login_flow/${this._step.flow_id}`, { fetch(`/auth/login_flow/${this._step.flow_id}`, {
method: 'POST', method: 'POST',
credentials: 'same-origin',
body: JSON.stringify(postData) body: JSON.stringify(postData)
}).then((response) => { }).then((response) => {
if (!response.ok) throw new Error(); if (!response.ok) throw new Error();

View File

@ -53,7 +53,7 @@ class HaPickAuthProvider extends EventsMixin(PolymerElement) {
connectedCallback() { connectedCallback() {
super.connectedCallback(); super.connectedCallback();
fetch('/auth/providers').then((response) => { fetch('/auth/providers', { credentials: 'same-origin' }).then((response) => {
if (!response.ok) throw new Error(); if (!response.ok) throw new Error();
return response.json(); return response.json();
}).then((authProviders) => { }).then((authProviders) => {

View File

@ -4,6 +4,7 @@ export default function fetchToken(clientId, code) {
data.append('grant_type', 'authorization_code'); data.append('grant_type', 'authorization_code');
data.append('code', code); data.append('code', code);
return fetch('/auth/token', { return fetch('/auth/token', {
credentials: 'same-origin',
method: 'POST', method: 'POST',
body: data, body: data,
}).then((resp) => { }).then((resp) => {

View File

@ -4,6 +4,7 @@ export default function refreshAccessToken(clientId, refreshToken) {
data.append('grant_type', 'refresh_token'); data.append('grant_type', 'refresh_token');
data.append('refresh_token', refreshToken); data.append('refresh_token', refreshToken);
return fetch('/auth/token', { return fetch('/auth/token', {
credentials: 'same-origin',
method: 'POST', method: 'POST',
body: data, body: data,
}).then((resp) => { }).then((resp) => {

View File

@ -41,6 +41,7 @@ function initPushNotifications() {
delete payload.data; delete payload.data;
} }
fetch('/api/notify.html5/callback', { fetch('/api/notify.html5/callback', {
credentials: 'same-origin',
method: 'POST', method: 'POST',
headers: new Headers({ 'Content-Type': 'application/json', headers: new Headers({ 'Content-Type': 'application/json',
Authorization: 'Bearer ' + jwt }), Authorization: 'Bearer ' + jwt }),

View File

@ -80,7 +80,7 @@ export function getTranslation(fragment, translationInput) {
// Create a promise to fetch translation from the server // Create a promise to fetch translation from the server
if (!translations[translationFingerprint]) { if (!translations[translationFingerprint]) {
translations[translationFingerprint] = translations[translationFingerprint] =
fetch(`/static/translations/${translationFingerprint}`, { credentials: 'include' }) fetch(`/static/translations/${translationFingerprint}`, { credentials: 'same-origin' })
.then(response => response.json()).then(data => ({ .then(response => response.json()).then(data => ({
language: translation, language: translation,
data: data, data: data,