7

在使用经典的 Azure 移动服务时,你曾经获得一个密钥以及移动服务应用程序的 URL。此密钥还用于探索后端站点上的 API 并用作密码。

使用新的 Azure 应用程序服务,您只需使用如下 URL 即可启动移动服务客户端

private static readonly MobileServiceClient MobileService = new MobileServiceClient("https://thecityapp.club");

没有可用于 Azure 移动服务的关键 *第二个参数。现在使用什么作为密码来探索 Web 上的 API?

4

2 回答 2

9

好极了,

对于应用程序服务/移动应用程序,不再使用/需要应用程序密钥,这就是它不再在门户上可用的原因。您可以使用上述代码实例化客户端,并在没有该信息的情况下开始使用服务 API。

有关身份验证,请参阅此文档:https ://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-windows-store-dotnet-get-started-users/

我希望这有帮助。

于 2016-01-06T18:10:17.893 回答
1

如果需要,您可以为 Azure 移动应用程序实施应用程序密钥。

您可以为 Azure 移动应用程序(如 Azure 移动服务)设置应用程序密钥。

1. 在 Azure 移动应用程序上打开应用程序设置

2. 向下滚动到App Settings添加这两行。

| zumo-api-key | 输入您的 API 密钥|

| MS_SkipVersionCheck | 真 |

3.然后点击保存

4.打开应用服务编辑器

5. 在主文件夹wwwroot上创建一个文件

6. 将您的文件命名为validateApiKey.js

// ----------------------------------------------------------------------------
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
// ----------------------------------------------------------------------------

module.exports = function (req, res, next) {
// Validate zumo-api-key header against environment variable.
// The header could also be validated against config setting, etc
var apiKey = process.env['zumo-api-key'];

if (apiKey && req.get('zumo-api-key') != apiKey)
    return res.status(401).send('This operation requires a valid api key');
else
    return next();
}

6. 将您的 API 脚本更新为,

[示例API.js]

var validateApiKey = require('../validateApiKey');
module.exports = {
    "get": [validateApiKey, function(request, response, next)
    {
        response.send(
        {
            message: "post"
        });
    }],
    "post": [validateApiKey, function(request, response, next)
    {
        response.send(
        {
            message: "post"
        });
    }]
};

[示例API.json]

{
  "get": {
    "access": "anonymous"
  },
  "post": {
    "access": "anonymous"
  },
  "put": {
    "access": "anonymous"
  },
  "patch": {
    "access": "anonymous"
  },
  "delete": {
    "access": "anonymous"
  }
}

不要忘记将权限更改为“匿名”

6. 将您的表脚本更新为,

[sampleTable.js]

var azureMobileApps = require('azure-mobile-apps'),
    validateApiKey = require('../validateApiKey');

// Create a new table definition
var table = azureMobileApps.table();

// Access should be anonymous so that unauthenticated users are not rejected
// before our custom validateApiKey middleware runs.
table.access = 'anonymous';

// validate api key header prior to execution of any table operation
    table.use(validateApiKey, table.execute);
// to require api key authentication for only one operation (in this case insert)
// instead of table.use(validateApiKey, table.execute) use:
// table.insert.use(validateApiKey, table.operation);

module.exports = table;

[sampleTable.json]

{
  "softDelete" : true,
  "autoIncrement": false,
  "insert": {
    "access": "anonymous"
  },
  "update": {
    "access": "anonymous"
  },
  "delete": {
    "access": "anonymous"
  },
  "read": {
    "access": "anonymous"
  },
  "undelete": {
    "access": "anonymous"
  }
}

不要忘记将权限更改为“匿名”

7. 完成!

调用 Azure 移动/Web 应用程序时不要忘记添加标头。

此外,您可以从 Github 上的这个存储库中看到更多信息。

https://github.com/thisisfatih/applicationKeyAzure/

于 2016-10-12T19:05:50.397 回答