Auth0 swift webview invalid request

Hi, I have an application iOS where I use auth0 login page. In this app, when I try to do access with google or apple, I have this error:

invalid_request. You may have pressed the back button, refreshed during login, opened too many login dialogs, or there is some issue with cookies, since we couldn’t find your session. Try logging in again from the application and if the problem persists please contact the administrator.

This problem occuor only for iOS app, if I try to login from web or from Android is working fine. I have a swift Webview file that manage this.

I tried to print cookies array and it is empty, I don’t know if this can be the error.

I tried also to update user agent but nothing.

Can you help me?

Thanks in advance.

The “invalid_request” error you are experiencing when trying to access your iOS app using Google or Apple login could be caused by a few factors. Here are some steps you can take to troubleshoot and resolve the issue:

  1. Verify Bundle Identifier: Ensure that the Bundle Identifier in your Xcode project matches the one configured in your Auth0 dashboard. Any discrepancy can cause issues with the authentication flow.

  2. Check Redirect URI: Double-check that the Redirect URI in your Auth0 dashboard matches the one specified in your iOS app’s code. It should be in the format “https://{YOUR_DOMAIN}/ios/{BUNDLE_IDENTIFIER}/callback”.

  3. Enable Universal Links: If you are using Apple login, make sure you have correctly set up Universal Links for your app. This allows authentication callbacks to be handled by the app instead of through a web browser.

  4. Check App Configuration: Review your Auth0 configuration in the iOS app to ensure it is correctly initialized, and the necessary scopes and connections are configured.

  5. Clear Cookies and Cache: If the issue persists, try clearing cookies and cache data on your iOS device. This can be done in the device’s Settings app, under Safari or Browser settings.

  6. Test on Different iOS Versions: Test the app on different iOS versions to see if the issue is specific to a particular version. It could be related to changes in iOS versions or Safari behaviour.

  7. Enable Debugging: Enable debugging in your iOS app to get more detailed error information. You can do this by setting the Auth0.debug flag to true before initializing the Auth0 library.

Hope this helps, do let me know how it goes

Thanks for help.

I tried your suggestions but I had no result. I did not understand the point 7: how can I enable debugging? Can you explain it better please?

For give you more informations, this is for now the code that I use to call the login interface in my app:

let launchUrl = SceneDelegate.universalLinkToLaunch ?? SceneDelegate.shortcutLinkToLaunch ?? rootUrl;
            SmartAirfield.webView.load(URLRequest(url: launchUrl))

In the past we not used the Auth0 package, I installed now and I’m trying also another approach with this function:

func login() {
      Auth0
        .webAuth()
        .start { result in
            
          switch result {
                  
            case .failure(let error):
              // The user either pressed the “Cancel” button
              // on the Universal Login screen or something
              // unusual happened.
              if error == .userCancelled {
                let alert = UIAlertController(
                  title: "Please log in.",
                  message: "You need to log in to use the app.",
                  preferredStyle: .alert)
                alert.addAction(
                  UIAlertAction(
                    title: NSLocalizedString(
                      "OK",
                      comment: "Default action"
                    ),
                    style: .default,
                    handler: { _ in
                      NSLog("Displayed the \"Please log in\" alert.")
                }))
                self.present(alert, animated: true, completion: nil)
              
              } else {
                print("An unexpected error occurred: \(error.localizedDescription)")
              }
            
            case .success(let credentials):
              // The user successfully logged in.
              self.userIsAuthenticated = true
              self.user = User.from(credentials.idToken)
                          
              DispatchQueue.main.async {
              }
                        
          } // switch
            
        } // start()
    }

but for now nothing. I’m new to swift programming.

Anyway, another detail is that the error that I described is shown when the user finish the login phase. For make an example: I open the app, I choose login with google, I put email and password, and after the login is successful the user is redirect in the page that give the error.