Unable to process request due to missing initial state. This may happen if browser sessionStorage is inaccessible or accidentally cleared. Some specific scenarios are - 1) Using IDP-Initiated SAML SSO. 2) Using signInWithRedirect in a storage-partitioned browser environment.
Description
Hi, I'm using OpenId Connect with an external salesforce provider, on IOS (swift) after calling the getCredentialWith method, every now and then I get the following message when logging in: "Unable to process request due to missing initial state. This may happen if browser sessionStorage is inaccessible or accidentally cleared. Some specific scenarios are - 1) Using IDP-Initiated SAML SSO 2) Using signInWithRedirect in a storage-partitioned browser environment."
On the next login attempt everything works. Help, I don't know what to do anymore. Thank you
Reproducing the issue
No response
Firebase SDK Version
10.25.0
Xcode Version
15.4
Installation Method
CocoaPods
Firebase Product(s)
Authentication
Targeted Platforms
iOS
Relevant Log Output
No response
If using Swift Package Manager, the project's Package.resolved
Expand Package.resolved snippet
Replace this line with the contents of your Package.resolved.
If using CocoaPods, the project's Podfile.lock
Expand Podfile.lock snippet
Replace this line with the contents of your Podfile.lock!
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Does anything at https://stackoverflow.com/q/67373448/556617 help?
no paulb777, i have try but nothing
@dennysoft it looks like your issue is related here. Have you tried checking the doc to use signInWithRedirect?
Rizafran, thanks, i have read this documentation, but the web side is a Salesforce authentication provider, that documentation refers to Firebase Web
Same issue:
<!DOCTYPE html>
<html>
<head>
<title>FirebaseUI with Compat</title>
<!-- Firebase App (the core Firebase SDK) is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/9.8.0/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.8.0/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.8.0/firebase-firestore-compat.js"></script>
<!-- Include FirebaseUI -->
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/4.8.0/firebase-ui-auth.css" />
<script src="https://www.gstatic.com/firebasejs/ui/4.8.0/firebase-ui-auth.js"></script>
<style>
/* Add some styling */
#firebaseui-auth-container, #welcome-container, #loader {
margin: 0 auto;
width: 300px;
text-align: center;
}
#sign-out-button {
display: none;
}
</style>
</head>
<body>
<h1>FirebaseUI with Compat</h1>
<div id="firebaseui-auth-container"></div>
<div id="welcome-container" style="display:none;">
<h2>Welcome, <span id="user-name"></span>!</h2>
<button id="sign-out-button">Sign Out</button>
</div>
<div id="loader">Loading...</div>
<script>
// Replace the following with your app's Firebase project configuration
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "localhost",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
appId: "YOUR_APP_ID",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Initialize the FirebaseUI Widget using Firebase.
const ui = new firebaseui.auth.AuthUI(firebase.auth());
// FirebaseUI config.
const uiConfig = {
callbacks: {
signInSuccessWithAuthResult: function(authResult, redirectUrl) {
// User successfully signed in.
return false; // Do not redirect.
},
uiShown: function() {
// The widget is rendered.
// Hide the loader.
document.getElementById('loader').style.display = 'none';
}
},
signInFlow: 'redirect',
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.FacebookAuthProvider.PROVIDER_ID,
firebase.auth.TwitterAuthProvider.PROVIDER_ID,
firebase.auth.GithubAuthProvider.PROVIDER_ID,
firebase.auth.EmailAuthProvider.PROVIDER_ID,
firebase.auth.PhoneAuthProvider.PROVIDER_ID
],
tosUrl: '<your-tos-url>', // Terms of service url
privacyPolicyUrl: '<your-privacy-policy-url>' // Privacy policy url
};
// Set persistence and then start FirebaseUI
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL)
.then(() => {
// Initialize the FirebaseUI Widget using Firebase.
ui.start('#firebaseui-auth-container', uiConfig);
})
.catch((error) => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.error('Persistence error', errorCode, errorMessage);
});
// Check the authentication state on page load and display the appropriate UI
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
document.getElementById('user-name').textContent = user.displayName || user.email;
document.getElementById('firebaseui-auth-container').style.display = 'none';
document.getElementById('welcome-container').style.display = 'block';
document.getElementById('sign-out-button').style.display = 'block';
} else {
// No user is signed in.
document.getElementById('firebaseui-auth-container').style.display = 'block';
document.getElementById('welcome-container').style.display = 'none';
document.getElementById('sign-out-button').style.display = 'none';
}
document.getElementById('loader').style.display = 'none';
});
// Sign out button functionality
document.getElementById('sign-out-button').addEventListener('click', function() {
firebase.auth().signOut().then(function() {
// Sign-out successful.
document.getElementById('firebaseui-auth-container').style.display = 'block';
document.getElementById('welcome-container').style.display = 'none';
document.getElementById('sign-out-button').style.display = 'none';
}).catch(function(error) {
// An error happened.
console.error('Sign out error', error);
});
});
</script>
</body>
</html>
Any update on this?
Just use the signInWithProvider method and give it an AppleAuthProvider object, which is bundled in the firebase_auth package.
Any update on this? I have this problem with iOS and oidc connected with an external provider. Once authentication is complete, and I get to firebase callback I get that error message. This happens with two different providers that implement oidc connect. However, on Firebase Android this problem only happened a few times while on iOS it is systematic.
A reproducible example would help
This solution works for me on Flutter (Android & iOS):
void _handleGoogleSignIn() async {
try {
final GoogleSignIn googleSignIn = GoogleSignIn();
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
if (googleUser != null) {
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
UserCredential userCredential =
await FirebaseAuth.instance.signInWithCredential(credential);
User? user = userCredential.user;
if (user != null) {
print('User signed in: ${user.email}');
}
}
} catch (e) {
print(e.toString());
}
}
https://pub.dev/packages/sign_in_with_apple#server This solved this issue here
The following patch makes it runnable without any errors for the case where the app transits to the Twitter/X app when logging in. The handling of Twitter/X for third-party apps is seemingly problematic. If it is not installed, the browser can process correctly. In the following code, the internal browser is used instead.
Intrinsically, this problem should be solved in the Twitter/X app.
FIRAuthURLPresenter.m
- if ([SFSafariViewController class]) {
- self->_safariViewController = [[SFSafariViewController alloc] initWithURL:URL];
- self->_safariViewController.delegate = self;
- [self->_UIDelegate presentViewController:self->_safariViewController
- animated:YES
- completion:nil];
- return;
- } else {
+// The SFSafariViewController code was temporarily commented out.
+// The Twitter/X app, which is opened automatically by the universal link, cannot handle the auth processing expectedly.
+// FIRAuthWebViewController and its WKWebView that has disabled the universal link internally must be used.
+// if ([SFSafariViewController class]) {
+// self->_safariViewController = [[SFSafariViewController alloc] initWithURL:URL];
+// self->_safariViewController.delegate = self;
+// [self->_UIDelegate presentViewController:self->_safariViewController
+// animated:YES
+// completion:nil];
+// return;
+// } else {
self->_webViewController = [[FIRAuthWebViewController alloc] initWithURL:URL delegate:self];
UINavigationController *navController =
[[UINavigationController alloc] initWithRootViewController:self->_webViewController];
[self->_UIDelegate presentViewController:navController animated:YES completion:nil];
- }
+// }
FIRAuthWebViewController.m
- decisionHandler(WKNavigationActionPolicyAllow);
+ decisionHandler(WKNavigationActionPolicyAllow + 2);
https://pub.dev/packages/sign_in_with_apple#server This solved this issue here
I was able to resolve the same error mentioned in this issue with Glitch. I would like to avoid dependence on another service, but am I stuck with Glitch as a workaround?
I got this issue on a Web app
@toddmueller you can implement same of Glitch yourself in your server
Just use the signInWithProvider method and give it an AppleAuthProvider object, which is bundled in the firebase_auth package.
@v-sheludchenko - I could be missing something but given that this issue was reported against the Firebase iOS SDK and the links you posted are to a Flutter library, I'm unsure how they're relevant.
@dennysoft is it fix ?
Facing same issue