gpt4 book ai didi

c# - 即使成功登录后,Azure 移动应用程序也会返回 401(未经授权)。

转载 作者:行者123 更新时间:2023-12-03 01:51:01 25 4
gpt4 key购买 nike

我正在使用 facebook 的自定义身份验证来让我的用户登录到应用程序服务。不幸的是,我在调用“InvokeApiAsync”时收到以下错误

“Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException:无法完成请求。(未经授权)”

我使用的以下代码适用于 NuGet 包的 1.x.x 分支,只有在更新后我才会收到此错误消息。

Newtonsoft.Json.Linq.JObject jToken = new Newtonsoft.Json.Linq.JObject();
jToken.Add("access_token", token);

var user = await _mobileService.LoginAsync(MobileServiceAuthenticationProvider.Facebook, jToken);

var result= await _mobileService.InvokeApiAsync<GetContactListRequest, GetContactListResponse>("GetContactList", new GetContactListRequest());

LoginAsync 部分正常工作,并且 user 变量包含具有 token 的用户(_mobileService.CurrentUser 也是如此)。当我调用“InvokeApiAsync”时,我收到了“未经授权”错误。

移动服务

[Authorize]
public class GetContactListController : ApiController
{
// POST api/CustomRegistration
public HttpResponseMessage Post(GetContactListRequest request)
{
try
{
return this.Request.CreateResponse(HttpStatusCode.OK, new GetContactListResponse());
}
catch (Exception ex)
{
return this.Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
}

有什么指点吗?

最佳答案

尝试为您的移动应用后端启用应用程序日志记录(您可以在门户中执行此操作)。如果问题出在平台身份验证管道中,那么您将获得有关身份验证失败的更多详细信息。否则,它更有可能出现在您的应用程序代码(客户端或服务器)中。

如果您有 Fiddler 跟踪,这也有助于诊断问题。

关于c# - 即使成功登录后,Azure 移动应用程序也会返回 401(未经授权)。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37082681/

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