新的Azure应用服务中,密钥在哪里?

7

在使用经典的Azure移动服务时,您会得到一个密钥和Mobile Service应用程序的URL。该密钥也用于探索后端网站上的API,并用作密码。

使用新的Azure App服务,您只需要以下URL即可实例化移动服务客户端

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

在Azure移动服务中,没有可用于密码探索Web API的第二个参数*a key。现在使用什么作为密码呢?


1
更新:该密钥被称为应用程序密钥,现在不再可用。 - Supreet
2个回答

9

1
相当令人沮丧,这个密钥至少已经过时了四个月,然而 HTML/JavaScript 客户端库的文档仍然说你需要一个 AppKey 来实例化 MobileServiceClient。像这样的东西使 Azure 的 “Easy Tables” 功能变得不那么容易。(https://azure.microsoft.com/en-us/documentation/articles/mobile-services-html-how-to-use-client-library/) - pettys
1
@pettys,很抱歉文档有点混乱。上面的链接仍然提到应用程序密钥的原因是该文档涵盖了移动服务而不是移动应用程序(应用程序密钥支持已被删除的地方)。正在进行一些工作,以更清晰地分离文档,避免混淆(我经常这样做)。 - Fabio Cavalcante
2
感谢您抽出时间回复 - 我很感激。不幸的是,我仍然希望我没有选择尝试使用Azure Mobile [App|Services]来完成这个非常小的项目。本以为这将是一个快速、有趣的副业项目,使用一个酷炫的新工具,但结果却是一次又一次的挫败,从Azure门户问题开始,尝试配置移动应用程序易表格以使用Azure存储作为后端 - 无法使其正常工作。很抱歉发牢骚 - 我希望这能有所帮助,祝您一切顺利,并感谢您在Stack Overflow社区的积极参与。 - pettys

1
你可以为Azure移动应用程序实现应用程序密钥。
像Azure移动服务一样,您可以为Azure移动应用设置应用程序密钥。
1. 在Azure移动应用程序上打开“应用程序设置”。
2. 滚动到“应用程序设置”,添加以下两行。 |zumo-api-key|输入您的API密钥| |MS_SkipVersionCheck|True|
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脚本更新为以下内容:

[sampleAPI.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"
        });
    }]
};

[sampleAPI.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/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接