我正在使用 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/