【问题标题】:Azure Mobile Services .NET Client with Custom Authentication Missing X-ZUMO-AUTH Header and Failing API Authentication具有自定义身份验证的 Azure 移动服务 .NET 客户端缺少 X-ZUMO-AUTH 标头和 API 身份验证失败
【发布时间】:2016-02-08 16:04:34
【问题描述】:

我有以下场景:

1) Azure 移动服务 API 2) 自定义认证 3) Web 和 Xamarin 客户端 4) 小型测试工具(使用 MSTest 的 .NET 应用)

通过自定义身份验证,我可以从浏览器和单元测试登录并取回适当的用户 ID 和令牌。

类似这样的:

  var user = await Connect.MobileClient
            .InvokeApiAsync<LoginRequest, MobileServiceUser>(
            "CustomLogin", new LoginRequest()
            {
                username = username,
                password = password
            });

然后我执行以下操作:

Connect.MobileClient.CurrentUser = user;

调试清楚地表明 userId 和 MobileServicesAuthenticationToken 设置正确。

当我在我的控制器上调用 POST 时,在控制器上的 Initialize 方法执行后,我被未经授权的人抛弃了。

几点说明:

1) 如果我从“尝试一下”(在注册、登录并将令牌值粘贴到 X-ZUMO-AUTH 标头中之后)执行 POST,一切都会顺利进行。 2) 同样,如果我删除
也没问题 [AuthorizeLevel(AuthorizationLevel.User)] 从控制器类或方法(都尝试过)。

这是失败的帖子(来自 Fiddler):

POST https://anapi.azure-mobile.net/tables/Organization__systemproperties=__createdAt%2C__updatedAt%2C__version%2C__deleted HTTP/1.1
X-ZUMO-FEATURES: TT
X-ZUMO-INSTALLATION-ID: dfddf760-ecef-49cb-8197-2faaaaa11502
X-ZUMO-APPLICATION: aaaaaauJOUyfFjjPmZpobTybtaaaaaa
Accept: application/json
User-Agent: ZUMO/1.3 (lang=Managed; os=Windows; os_version=6.2.0.9200;     arch=Win32NT; version=1.3.30324.0)
X-ZUMO-VERSION: ZUMO/1.3 (lang=Managed; os=Windows; os_version=6.2.0.9200;     arch=Win32NT; version=1.3.30324.0)
Content-Type: application/json; charset=utf-8
Host: anapi.azure-mobile.net
Content-Length: 110
Expect: 100-continue
Accept-Encoding: gzip

{"OrganizationId":0,"Name":"International Bozo, Inc.","Address":"Dallas, Texas","Accounts":null,"Courses":null}

“试试这个”HTTP POST 包含带有适当令牌的 X-ZUMO-AUTH 标头。

【问题讨论】:

    标签: authentication azure-mobile-services


    【解决方案1】:

    您需要在调用 client.invokeAPI 方法之前设置 client.currentUser 属性(从您的问题中可以看出您正在执行其他顺序)

    然后从 user.MobileAuthenticationToken 填充 X-ZUMO-AUTH 标头 如此处所示: https://github.com/Azure/azure-mobile-services/blob/master/sdk/Managed/src/Microsoft.WindowsAzure.MobileServices/Http/MobileServiceHttpClient.cs#L566-L569

    【讨论】:

    • 感谢您的回复。我的订单是正确的。这个问题现在已经解决了,虽然我不知道是什么解决了它。运行调试器时可能是证书问题,中间有提琴手。
    • 肯定 fiddler 会为你打破这些东西。但是你可以在设置中设置证书。
    猜你喜欢
    • 2014-03-12
    • 1970-01-01
    • 2011-11-04
    • 1970-01-01
    • 2016-01-23
    • 2016-01-18
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    相关资源
    最近更新 更多