简体   繁体   中英

Error “Safari cannot open the page because the address is invalid” with Azure AD B2C

We're using Azure AD B2C with our Xamarin Forms app. I've got this working on Android and had it working on iOS . For some strange reason though I'm now getting this error when trying to login on iOS .

在此输入图像描述

The login screen comes up, the user enters their username and password, but then they get the error. Looking at the Azure sign-ins for the AD I can see that Azure has successfully signed-in the user. This suggests the error is with the redirection back to the app from Azure .

I've configured the app according to this example especially step 6. Like I said though, I had this working previously. I haven't changed any of the login code since getting it working, so what else could have caused it to break?

You can try to add this method to your AppDelegate.cs

public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
    {
        if (HandleOpenURL(application, url)){
            return true;
        }

        //return base.OpenUrl(application, url, sourceApplication, annotation);
        return false;
    }

I eventually found the answer by referring to this article . The pertinent section is the iOS section describing updating the info.plist file. The example article I used to integrate with Azure AD B2C (see my OP above) stated that I should use a text editor such as VS Code to update this file. However, the article here states I should update the file using Visual Studio . A comparison of the two files shows differences between the values entered into info.plist .

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>My URL scheme</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>msalmyapplicationid-goes-here</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>None</string>
    </dict>
</array>

This logged me in but then I immediately got the following error which kicked me out of the app.

The resource could not be loaded because the App Transport Security policy requires the use of a secure connection

I added the following to info.plist whihc has resolved the error.

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

All is now working and users can log into the app using iOS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM