简体   繁体   English

使用Azure AD B2C时出现错误“Safari无法打开页面,因为地址无效”

[英]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. 我们将Azure AD B2C与我们的Xamarin Forms应用程序一起使用。 I've got this working on Android and had it working on iOS . 我已经在Android上使用它,并让它在iOS上工作。 For some strange reason though I'm now getting this error when trying to login on iOS . 出于一些奇怪的原因,虽然我在尝试登录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. 查看AD的Azure登录,我可以看到Azure已成功登录用户。 This suggests the error is with the redirection back to the app from Azure . 这表明错误是从Azure重定向回应用程序。

I've configured the app according to this example especially step 6. Like I said though, I had this working previously. 我根据这个例子配置了应用程序,尤其是第6步。就像我说的那样,我之前有过这个工作。 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 您可以尝试将此方法添加到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. 相关部分是描述更新info.plist文件的iOS部分。 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. 我以前与Azure AD B2C集成的示例文章(参见上面的OP)声明我应该使用文本编辑器(如VS Code)来更新此文件。 However, the article here states I should update the file using Visual Studio . 但是,这篇文章指出我应该使用Visual Studio更新文件。 A comparison of the two files shows differences between the values entered into info.plist . 两个文件的比较显示输入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 无法加载资源,因为App Transport Security策略要求使用安全连接

I added the following to info.plist whihc has resolved the error. 我将以下内容添加到info.plist whihc已解决错误。

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

All is now working and users can log into the app using iOS. 现在一切正常,用户可以使用iOS登录应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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