简体   繁体   English

Xamarin Azure AD B2C登录,卡在登录页面

[英]Xamarin Azure AD B2C login, stuck at login page

I am attempting to log into a xamarin mobile application using AAD B2C authentication.我正在尝试使用 AAD B2C 身份验证登录 xamarin 移动应用程序。 I have created the solution in visual studio.我已经在 Visual Studio 中创建了解决方案。 In Azure I have created my tenant, registered a native application and a web application (Properties below) and am trying to debug my application.在 Azure 中,我创建了我的租户,注册了本机应用程序和 web 应用程序(下面的属性),并且正在尝试调试我的应用程序。 Currently, I am redirected to the B2Clogin page and can enter a username and password.目前,我被重定向到 B2Clogin 页面,可以输入用户名和密码。 Then it processes the request and stays on that page indefinitely.然后它处理请求并无限期地停留在该页面上。 When I check the azure portal, I can see the account I created through the B2C login page and I can see successful sign-ins but the B2C login page does not redirect back to my application.当我检查 azure 门户时,我可以看到我通过 B2C 登录页面创建的帐户,并且可以看到成功登录,但 B2C 登录页面没有重定向回我的应用程序。 I'm also using AuthenticationContinuationHelper in AppDelegate.cs as well as in MainActivity.cs我还在 AppDelegate.cs 和 MainActivity.cs 中使用 AuthenticationContinuationHelper

In App.cs在 App.cs 中

````
     public static string B2CClientEndpoint = "<UserFlowAuthorizationEndpoint>"; //the endpoint generated when we ran the user flow.
            public static string[] B2CScopes = { "<RegisteredWebAPI.Read>" };

       PCAB2C = PublicClientApplicationBuilder.Create(B2CClientID)
                    .WithB2CAuthority("https://<DirectoryName>.b2clogin.com/tfp/<DirectoryName>.onmicrosoft.com/<Policy>")
                    .WithIosKeychainSecurityGroup("<SecurityGroup>")
                    .WithRedirectUri("msal<ApplicationID>://auth")
                    .Build();

````

In Controller class在 Controller class

````C#

     IAccount User = Accounts.FirstOrDefault();
                    if (Accounts.Count() != 0)
                    {
                        Result = await App.PCAB2C.AcquireTokenSilent(App.B2CScopes, User)
                       .WithB2CAuthority("<B2CSignInAuthority>")
                       .ExecuteAsync();
                    }
                    else
                    {
                        User = Accounts.FirstOrDefault();
                        Result = await App.PCAB2C.AcquireTokenInteractive(App.B2CScopes)
                            .WithB2CAuthority("<B2CSignInAuthority>")
                            .WithParentActivityOrWindow(App.ParentWindow)
                            .WithAccount(User)
                            .ExecuteAsync();
                    }

```

According to the official documentation of AD B2C,根据AD B2C的官方文档

To refresh and get tokens in a hidden iframe, use prompt=none to ensure that the iframe does not get stuck on the sign-in page, and returns immediately.刷新并获取隐藏 iframe 中的令牌,使用 prompt=none 确保 iframe 不会卡在登录页面,并立即返回。

So essentially, verify your URL and don't forget to review the Error response!因此,基本上,验证您的 URL 并且不要忘记查看错误响应!

I've had this problem and resolved it by reducing the minimum target Android & iOS versions.我遇到了这个问题,并通过减少最小目标 Android 和 iOS 版本来解决它。

ie: Android 8.0 and higher & iOS min 13.0即:Android 8.0 及更高版本 & iOS min 13.0

Apparently, MSAL has a min OS version to target in Xamarin Forms builds.显然,MSAL 在 Xamarin Forms 构建中有一个最小操作系统版本。

在此处输入图像描述

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

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