SFSafariViewController is not returning to iOS app

Sumit Kumar 25 Reputation points
2024-02-25T03:16:23.73+00:00

Hi, I am working on the MSAL SSO login when I set the .safariViewController in webViewParameters and try to login then it is not returning to the iOS App, it just show DONE button on SafariViewController. I have also checked the other thread and everyone is saying that we need to use below line := func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print("Received Callback in App delegate (options) (url)")
return MSALPublicClientApplication.handleMSALResponse(url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String)
}

I have also added above code and my redirect url is also correct but still it is not working.

Can anyone help me on this issue. Code : = self.webViewParameters = MSALWebviewParameters(authPresentationViewController: self)
self.webViewParameters?.webviewType = .safariViewController
self.webViewParameters?.presentationStyle = .fullScreen info.plist:==

<key>CFBundleURLTypes</key>
   <array>
   	<dict>
   		<key>CFBundleURLSchemes</key>
   		<array>
   			<string>msauth.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
   		</array>
   	</dict>
   </array>
   <key>LSApplicationQueriesSchemes</key>
   <array>
       <string>msauth</string>
   	<string>msauthv2</string>
   	<string>msauthv3</string>
   </array>
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Identity Manager
{count} votes

Accepted answer
  1. Akshay-MSFT 17,956 Reputation points Microsoft Employee Moderator
    2024-02-27T11:43:18.63+00:00

    @Sumit Kumar
    From above description and comments I could see that you have already been using the application(_:open:options:) method in AppDelegate which is required for Controller to return to the app. Kindly validate the following checks and confirm if this helps you.

    1. Check the redirect URI in your MSAL configuration to make sure it matches the URI scheme of your iOS app. You can find the URI scheme of your app in the Info.plist file under the URL types section.
    2. Make sure that you are dismissing the SFSafariViewController in the completion block of the acquireToken method. For example:
    application.acquireToken(with: tokenParameters) { (result, error) in
        if let error = error {
            print("Error acquiring token: \(error)")
            return
        }
        
        if let result = result {
            print("Access token: \(result.accessToken)")
            // Do something with the access token
        }
        
        // Dismiss the SFSafariViewController
        self.dismiss(animated: true, completion: nil)
    }
    
    1. Kindly validate the version of MSAL you have been using try to use the latest one and confirm the behavior.

    Please "Accept the answer (Yes)" and "share your feedback ". This will help us and others in the community as well.

    Thanks, Akshay Kaushik

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.