简体   繁体   English

Azure AD B2C 上 Xamarin.Forms 抛出错误 B2C '权限' Uri 应该至少有 3 个段

[英]Azure AD B2C on Xamarin.Forms throwing error B2C 'authority' Uri should have at least 3 segments

I am trying to integrate Azure AD B2C into a Xamarin.Forms app.我正在尝试将 Azure AD B2C 集成到 Xamarin.Forms 应用程序中。 I am following THIS GUIDE as a starter.我按照本指南作为初学者。 I have created Azure AD B2C tenant.我创建了 Azure AD B2C 租户。 When I open the endpoints of the tenant here is what I see当我打开租户的端点时,我看到的是

在此处输入图像描述

As you can see the general pattern for URL is https://TENANT.b2clogin.com/TENANT.onmicrosoft.com/<policy-name>/如您所见,URL 的一般模式是https://TENANT.b2clogin.com/TENANT.onmicrosoft.com/<policy-name>/

However, inside the sample the URL is formed differently: https://TENANT.b2clogin.com/tfp/TENANT.onmicrosoft.com/<policy-name>/但是,在样本内部,URL 的形成方式不同: https://TENANT.b2clogin.com/tfp/TENANT.onmicrosoft.com/<policy-name>/

Notice the tfp bit.注意tfp位。

If I remove the tfp part from the URL formation, as soon as these lines are executed如果我从 URL 格式中删除tfp部分,则只要执行这些行

 var builder = PublicClientApplicationBuilder.Create(B2CConstants.ClientID)
                .WithB2CAuthority(B2CConstants.AuthoritySignInSignUp)
                .WithIosKeychainSecurityGroup(B2CConstants.IOSKeyChainGroup)
                .WithRedirectUri($"msal{B2CConstants.ClientID}://auth");

I receive the following exception我收到以下异常

System.ArgumentException: B2C 'authority' Uri should have at least 3 segments in the path (i.e. https://<host>/tfp/<tenant>/<policy>/...)

Obviously, the MSAL.NET API expects the the URI should contain the tfp bit, but the endpoints are really without that.显然,MSAL.NET API 期望 URI 应该包含tfp位,但端点确实没有。

I am using the the 4.17.1 version of Microsoft.Identity.Client .我正在使用4.17.1版本的Microsoft.Identity.Client

It does seem that the latest APIs in MSAL.NET are not compatible with the latest Azure AD B2C. MSAL.NET 中的最新 API 似乎与最新的 Azure AD B2C 不兼容。 Is there any workaround?有什么解决方法吗?

It appears I was doing it wrong.看来我做错了。 I shouldn't have used the endpoints from the B2C itself, rather I should have created specific iOS & Android app registrations.我不应该使用 B2C 本身的端点,而是应该创建特定的 iOS 和 Android 应用程序注册。 Here's what I have done.这就是我所做的。

  1. I have registered new public client/native application我已经注册了新的公共客户端/本机应用程序
  2. I have added iOS & Android platforms with correct bundle IDs我添加了具有正确捆绑 ID 的 iOS 和 Android 平台
  3. After this, I have opened app specific platform registration details在此之后,我打开了特定于应用程序的平台注册详细信息
  4. I have copied the client id & redirect uri from there.我已经从那里复制了客户端 ID 和重定向 uri。
  5. Replaced the redirect URIs for each platform with correct values将每个平台的重定向 URI 替换为正确的值
  6. Used the url that comes with 'tfp' in it使用了带有“tfp”的 url

After these steps all worked OK.完成这些步骤后,一切正常。

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

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