gpt4 book ai didi

xamarin - 如何集成新的 AD B2C 和 C# Azure 移动客户端库?

转载 作者:行者123 更新时间:2023-12-02 16:10:00 25 4
gpt4 key购买 nike

我已经保护了我的 API 应用程序,并使用我在此处找到的示例应用程序成功测试了我的 ADB2C 流程:https://github.com/Azure-Samples/active-directory-b2c-xamarin-native 。使用该结构,我可以触发登录过程,然后访问 protected API 调用。

但是,为了方便起见,我还想使用 WindowsAzure.Mobile sdk。这里暗示:https://cgillum.tech/2016/08/10/app-service-auth-and-azure-ad-b2c-part-2/您可以从该类中的 LoginAsync 触发 B2C 流程,但当我以这种方式调用它时,它什么也不做。

我还发现了https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-how-to-use-client-library/ (滚动到“使用 Active Directory 身份验证库对用户进行身份验证”)我在其中替换了用于获取 token 的 MSAL 调用。这会触发登录流程,我获得一个好的 token 并返回声明,然后将其放入一些 JSON 中并像这样传递它:

AuthenticationResult ar = await App.PCApplication.AcquireTokenSilentAsync(App.Scopes, "", App.Authority, App.SignUpSignInpolicy, false);
JObject payload = new JObject();
payload["access_token"] = ar.AccessToken;
user = await App.MobileService.LoginAsync(
MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, payload);

对 LoginAsync 的调用会抛出异常

{Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: You do not have permission to view this directory or page.
at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient+<ThrowInvalidResponse>d__18.MoveNext () [0x0022f] in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
(snip)

它们不是设计来一起工作的吗?这些是不同种类的代币吗?我使用 B2C 的原因是因为我真的不想知道所有 OAUTH 的东西:)

最佳答案

对于 B2C,您实际上取回的是 ID token 而不是访问 token ,并且我相信 ar.AccessToken 属性将为 null。此属性似乎也在最新版本的 MSAL 中消失了。

我怀疑您只需将有效负载更新为“authenticationToken”并使用ar.IdToken

我不确定您是否可以继续使用有效负载中的“access_token” key ,但也许可以。如果没有,请尝试使用“authenticationToken”。

关于xamarin - 如何集成新的 AD B2C 和 C# Azure 移动客户端库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39112939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com