c# - Azure 移动应用程序参与 Xamarin 身份验证

标签 c# azure xamarin.android azure-mobile-services

我正在使用 Xamarin Forms 身份验证和 Auth0。后端服务是Azure移动应用程序。我正在尝试通过以下方式将授权 token 传回服务:

            MobileServiceUser usr = new MobileServiceUser(User.UserName);
            usr.MobileServiceAuthenticationToken = User.jwt;
            App.client.CurrentUser = usr;

我还没有在我的 Azure 应用程序中处理这个问题。当我按上述方式传递用户时,我在 Xamarin 项目中遇到以下错误:

Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The request could not be completed. (Unauthorized)

事实上,我已经在我的 Controller 中声明了匿名访问:

[AuthorizeLevel(AuthorizationLevel.Anonymous)]
public class MovementController : TableController<MoveHeaderDto>

我该如何在我的 Azure 移动应用程序中处理 MobileServiceUser?

最佳答案

我相信您看到的 401 是因为 token 不是预期的格式并且无法验证。

MobileServiceAuthenticationToken 属性是移动应用程序网关本身颁发的 JWT。您需要调用带有额外 token 参数的 loginAsync() 方法重载,并传入从 Auth0 获取的 JWT。

loginAsync 方法将设置 MobileServiceUser,这将附加到对您的服务的调用。请注意,对于 Xamarin 表单,您需要有一个自定义渲染器,以便使用适合平台的正确 View 元素。这类似于 this blog post适用于 ADAL 库。

关于c# - Azure 移动应用程序参与 Xamarin 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31554504/

相关文章:

c# - 将未加密的标签数据附加到加密文件

javascript - 如何使用 Node.js 在 Azure Application Insights 中禁用采样

azure - 将 Azure 日志工作区与数据收集规则 (Terraform) 连接

c# - 获取可绘制资源

c# - 如何在 windows 8 facebook 应用程序中邀请好友?

c# - Entity Framework 为数据库中默认定义的 NOT NULL 列生成值

c# - 我应该如何用科学记数法(+301)解析一个非常大的数字?

azure - Azure Monitor 'Response time' 和 AppInsights 'Duration' 之间有什么区别?

android - Java.IO.File 到 C# 中的 System.IO.Stream?

android - 可绘制 xml 资源的 Xamarin.Forms Android Resources$NotFoundException