Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web Browser Dismissing Automatically When App Goes to Background During Login (MSAL) #2381

Open
vinaykumar0339 opened this issue Nov 6, 2024 · 3 comments
Assignees
Labels

Comments

@vinaykumar0339
Copy link

  • When the login process is initiated using MSAL and the user moves the app to the background, the browser automatically dismisses
  • Upon returning to the app, an endless loader UI is displayed. If the user clicks the back button, the login process is restarted. (This is an infinite loader and the back button click is from my app
  • Restarting the login process causes the error "Only one interactive session is allowed at a time", which persists until the app is killed and relaunched.
reference.video.mov
@ameyapat ameyapat self-assigned this Nov 6, 2024
@ameyapat
Copy link
Contributor

ameyapat commented Nov 6, 2024

@vinaykumar0339 we can't replicate the issue with our test app. Can you provide MSAL logs for your issue? Are you sure the view controller is not deallocated before the callback is called?

@vinaykumar0339
Copy link
Author

@ameyapat Thanks for the update.

I found the root cause.
The below code causes the model to be dismissed.

- (void)applicationWillEnterForeground:(UIApplication *)application
{
  // This should be omitted if your application presents a lock screen
  // in -applicationDidEnterBackground:
  [self.window.rootViewController dismissViewControllerAnimated:NO completion:NULL];
}

One query. Can we open the browser like a normal push screen instead of a presenter Modal sheet? What ever the viewController i given to MSALWebviewParameters it always showing as a sheet. is there any way to open it as normal view?

My Application was Built with react native.
This is the below code snippet.

@objc(login:reject:)
  func login(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
    guard let msalApplication = msalApplication else {
      // INFO: not required to show in ui. this scenario will not happen just fallback code
      reject(MSAL_INITIALIZE_MSAL_APPLICATION_ERROR, "Please Initialize Application Before loginging", nil)
      return
    }

    DispatchQueue.main.async { [weak self] in
      guard let presentedViewController = RCTPresentedViewController(), let strongSelf = self else {
        // INFO: not required to show in ui. this scenario will not happen just fallback code
        reject(self?.MSAL_RCT_PRESENTED_VIEW_CONTROLLER_ERROR, "RCTPresentedViewController Not Found", nil)
        return
      }

      let webParameters = MSALWebviewParameters(authPresentationViewController: presentedViewController)

      let interactiveParameters = MSALInteractiveTokenParameters(scopes: strongSelf.scopes, webviewParameters: webParameters)
      interactiveParameters.promptType = .selectAccount
      interactiveParameters.extraQueryParameters = strongSelf.queryParams

      msalApplication.acquireToken(with: interactiveParameters) { result, error in
        guard let authResult = result, error == nil else {
          let nsError = error! as NSError
          reject("\(nsError.code)", "SomeThingWentWrong".localized(), nsError)
          return
        }
        strongSelf.handleAcquireToken(with: authResult, resolve: resolve)
      }
    }

  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants