8000 Add auto-sign-in in the custom token generator sample. · rasata/quickstart-js@8328dec · GitHub
[go: up one dir, main page]

Skip to content

Commit 8328dec

Browse files
author
Nicolas Garnier
committed
Add auto-sign-in in the custom token generator sample.
Change-Id: I2fbbe8d2ef72bafa86453e35790338edeec45fe2
1 parent 6301b9d commit 8328dec

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

auth/customauth.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,19 @@
120120
document.getElementById('quickstart-sign-in').addEventListener('click', toggleSignIn, false);
121121
}
122122

123+
function getHashValue(key) {
124+
var matches = location.hash.match(new RegExp(key+'=([^&]*)'));
125+
return matches ? matches[1] : null;
126+
}
127+
123128
window.onload = function() {
124129
initApp();
130+
131+
// If a token has been passed in the hash fragment we display it in the UI and start the sign in process.
132+
document.getElementById('tokentext').value = getHashValue('token') || '';
133+
if (document.getElementById('tokentext').value) {
134+
firebase.auth().signInWithCustomToken(getHashValue('token'));
135+
}
125136
};
126137
</script>
127138
</head>

auth/exampletokengenerator/auth.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
document.getElementById('tokenbox').textContent = sJWT;
7272
console.log(sJWT);
7373

74-
var link = '<a href="../index.html?tok=' + sJWT + '">Use this token in the web custom auth example</a>';
74+
var link = '<a href="../customauth.html#token=' + sJWT + '">Use this token in the web custom auth example</a>';
7575
document.getElementById('linktokenbox').innerHTML = link;
7676
}
7777

@@ -131,9 +131,9 @@ <h2 class="mdl-card__title-text">Token Generator</h2>
131131
</div>
132132
<div class="mdl-card__supporting-text mdl-color-text--grey-600" id="notoken">
133133
<p>
134-
In order to generate a token you'll need to use a service account JSON file provided
135-
by the <a href="https://console.developers.google.com">Google Developers Console</a> view
136-
of your Firebase project. We recommend that once you're done testing with this tool you
134+
In order to generate a token you'll need to use a service account JSON file provided by the
135+
<a href="https://console.developers.google.com/apis/credentials/serviceaccountkey?project=_">Google Developers Console</a>
136+
view of your Firebase project. We recommend that once you're done testing with this tool you
137137
delete the service account you made, and create a fresh one for the integration with your
138138
actual authentication system.
139139
</p>

0 commit comments

Comments
 (0)
0