I am using Firebase SAML for my application with base authentication services from Azure AD which contains my organisations users details. I am also using AWS Cognito for providing the SAML as this app will be served through AWS in the end. Below is my code for Index.js where I have imported all firebase resource and configured the code for signing in with SAML:
// SAML Authentication Attempt
//Setting session persistence
setPersistence(auth, browserSessionPersistence)
.then(() => {
console.log("Session persistence set to browserSessionPersistence");
})
.catch((error) => {
// Handle Errors here.
console.error("Error setting persistence", error);
// Fallback to inMemoryPersistence if browserSessionPersistence fails
setPersistence(auth, inMemoryPersistence)
.then(() => {
console.log("Fallback to inMemoryPersistence");
})
.catch((error) => {
console.error("Error setting inMemory Persistence", error)
})
})
// SAML
function ssoSignIn() {
const provider = new SAMLAuthProvider('saml.saml-aws-iam');
signInWithRedirect(auth, provider)
.catch((error) => {
console.error("Error during signInWithRedirect:", error)
})
};
document.getElementById("ssoButton").addEventListener("click", (event) => {
event.preventDefault(); //Prevent Form Submission
ssoSignIn();
});
// Loading DOM before attaching event listener
document.addEventListener('DOMContentLoaded', () => {
const ssoButton = document.getElementById("ssoButton");
if (ssoButton) {
ssoButton.addEventListener('click', (event) => {
event.preventDefault();
ssoSignIn();
})
} else {
console.error("ssoButton not found in the DOM");
}
// Check for redirect result after redirecting back from the SAML Provider
getRedirectResult(auth)
.then((result) => {
if (result && result.user) {
console.log("User signed in with SSO:", result.user);
// Redirect
window.location.href = "dashboard.html";
} else {
console.log("No user found after redirect. Result:", result);
}
})
.catch((error) => {
console.error("Error during getRedirectResult:", error);
})
})
onAuthStateChanged(auth, (user) => {
if (user) {
console.log("User is signed in:", user);
window.location.href = "dashboard.html";
} else {
console.log("No user is signed in.")
}
})
Based on the code, I expect the user to be redirect to ‘Dashboard.html’ or even for one of the console.log to return user’s details. Instead, I am receiving the following error:
[Error] Error during getRedirectResult: – FirebaseError: Firebase: All <AudienceRestriction>s should contain the SAML RP entity ID: ' urn:amazon:cognito:sp:[MY-USER-POOL-ID]'. (auth/invalid-credential).
FirebaseError: Firebase: All <AudienceRestriction>s should contain the SAML RP entity ID: ' urn:amazon:cognito:sp:eu-west-2_cD0DvWqD2'. (auth/invalid-credential).
(anonymous function) (index.js:126)
I cannot seem to find the answer to this in any existing forum or through documents, given all redirects are working and that the user log is showing that a user has been logged is confusing as to why this is not working.