Skip to content

Commit

Permalink
Fill in SAMLResponse nameId for pre-populated users (#3946)
Browse files Browse the repository at this point in the history
A bit of cleanup from #3927. Widget should fill in the SAMLResponse correctly even for users that were signed in previously.

Corresponding internal bug: b/192387796
  • Loading branch information
lisajian authored Dec 15, 2021
1 parent 6cebe6a commit a65e5f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/emulator/auth/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function registerHandlers(
<span class="mdc-list-item__text"><span class="mdc-list-item__primary-text">${
info.displayName || "(No display name)"
}</span>
<span class="mdc-list-item__secondary-text fallback-secondary-text">${
<span class="mdc-list-item__secondary-text fallback-secondary-text" id="reuse-email">${
info.email || ""
}</span>
</li>`
Expand Down
8 changes: 4 additions & 4 deletions src/emulator/auth/widget_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,17 @@ var reuseAccountEls = document.querySelectorAll('.js-reuse-account');
if (reuseAccountEls.length) {
[].forEach.call(reuseAccountEls, function (el) {
var urlEncodedIdToken = el.dataset.idToken;
const decoded = JSON.parse(decodeURIComponent(urlEncodedIdToken));
el.addEventListener('click', function (e) {
e.preventDefault();
finishWithUser(urlEncodedIdToken);
finishWithUser(urlEncodedIdToken, decoded.email);
});
});
} else {
document.querySelector('.js-accounts-help-text').textContent = "No " + formattedProviderId + " accounts exist in the Auth Emulator.";
}
function finishWithUser(urlEncodedIdToken) {
function finishWithUser(urlEncodedIdToken, email) {
// Use widget URL, but replace all query parameters (no apiKey etc.).
var url = window.location.href.split('?')[0];
// Avoid URLSearchParams for browser compatibility.
Expand All @@ -176,7 +177,6 @@ function finishWithUser(urlEncodedIdToken) {
// Save reasonable defaults for SAML providers
if (isSamlProvider) {
var email = document.getElementById('email-input').value;
url += '&SAMLResponse=' + encodeURIComponent(JSON.stringify({
assertion: {
subject: {
Expand Down Expand Up @@ -234,7 +234,7 @@ document.getElementById('main-form').addEventListener('submit', function(e) {
if (screenName) claims.screenName = screenName;
if (photoUrl) claims.photoUrl = photoUrl;
finishWithUser(createFakeClaims(claims));
finishWithUser(createFakeClaims(claims), claims.email);
}
});
Expand Down

0 comments on commit a65e5f0

Please sign in to comment.