Skip to content

Commit 8545959

Browse files
authored
Firebase functions 'redirect' & 'token' accessed using the same domain as the Firebase Hosting site. Makes cookies first party. (#849)
1 parent 06cc58c commit 8545959

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

instagram-auth/firebase.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
"rules": "database.rules.json"
44
},
55
"hosting": {
6-
"public": "public"
6+
"public": "public",
7+
"rewrites": [
8+
{
9+
"source": "/redirect",
10+
"function": "redirect"
11+
},
12+
{
13+
"source": "/token",
14+
"function": "token"
15+
}
16+
]
717
}
818
}

instagram-auth/public/popup.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@
6868
document.body.innerText = 'Error back from the Instagram auth page: ' + error;
6969
} else if(!code) {
7070
// Start the auth flow.
71-
window.location.href = 'https://us-central1-' + getFirebaseProjectId() + '.cloudfunctions.net/redirect';
71+
window.location.href = '/redirect';
7272
} else {
7373
// Use JSONP to load the 'token' Firebase Function to exchange the auth code against a Firebase custom token.
7474
const script = document.createElement('script');
7575
script.type = 'text/javascript';
7676
// This is the URL to the HTTP triggered 'token' Firebase Function.
7777
// See https://firebase.google.com/docs/functions.
78-
var tokenFunctionURL = 'https://us-central1-' + getFirebaseProjectId() + '.cloudfunctions.net/token';
78+
var tokenFunctionURL = '/token';
7979
script.src = tokenFunctionURL +
8080
'?code=' + encodeURIComponent(code) +
8181
'&state=' + encodeURIComponent(state) +

linkedin-auth/firebase.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
"rules": "database.rules.json"
44
},
55
"hosting": {
6-
"public": "public"
6+
"public": "public",
7+
"rewrites": [
8+
{
9+
"source": "/redirect",
10+
"function": "redirect"
11+
},
12+
{
13+
"source": "/token",
14+
"function": "token"
15+
}
16+
]
717
}
818
}

linkedin-auth/public/popup.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@
6868
document.body.innerText = 'Error back from the LinkedIn auth page: ' + error;
6969
} else if(!code) {
7070
// Start the auth flow.
71-
window.location.href = 'https://us-central1-' + getFirebaseProjectId() + '.cloudfunctions.net/redirect';
71+
window.location.href = '/redirect';
7272
} else {
7373
// Use JSONP to load the 'token' Firebase Function to exchange the auth code against a Firebase custom token.
7474
const script = document.createElement('script');
7575
script.type = 'text/javascript';
7676
// This is the URL to the HTTP triggered 'token' Firebase Function.
7777
// See https://firebase.google.com/docs/functions.
78-
var tokenFunctionURL = 'https://us-central1-' + getFirebaseProjectId() + '.cloudfunctions.net/token';
78+
var tokenFunctionURL = '/token';
7979
script.src = tokenFunctionURL +
8080
'?code=' + encodeURIComponent(code) +
8181
'&state=' + encodeURIComponent(state) +

0 commit comments

Comments
 (0)