Azure 移动应用服务 API 密钥

Azure Mobile App Service APIkey

我创建了一个当前可访问的 Azure 移动应用服务 'Anonymously'

Anonymous access is enabled on the App Service app. Users will not be prompted for login.

为了确保安全,我可以启用 App Service Authentication,这将要求用户登录

但这不是我想要的 - 此应用程序中的数据仅由应用程序访问,无需每个用户在使用前登录我的应用程序。

所以你可能会说,在这种情况下,Anonymous access 很好,但我想用至少像 API Key 这样的东西来限制它,这样我就可以访问 API我的应用程序可以使用它来访问数据以防止随机请求,因为任何人都可以使用 Postman 并开始获取数据而无需任何身份验证。

所以简而言之,我不需要个人用户身份验证,但至少需要一个 API 密钥来确保只有从我的应用程序发出的请求经过身份验证,而没有其他任何内容。

我在我的移动应用程序中使用以下内容来创建连接并进行离线同步等

MobileServiceClient client = new MobileServiceClient(applicationURL);

知道我该怎么做吗?

FYI. My server side backend is in C#

由于您使用的是 Azure 移动应用程序,根据您的要求,您可以利用 Custom Authentication 构建您的 CustomAuthController 以登录并为特定用户生成 JWT 令牌,无需用户交互。日志记录的核心代码片段如下所示:

MobileServiceClient client = new MobileServiceClient("https://{your-mobileapp-name}.azurewebsites.net/");
client.LoginAsync("custom", JObject.FromObject(new{Username="***",Password="***"}));

注:如上教程所述:

You must turn on Authentication / Authorization in your App Service. Set the Action to take when request is not authenticated to Allow Request (no action) and do not configure any of the supported authentication providers.

并且您必须为需要授权访问的控制器/操作显式添加 [Authorize] 属性。您可以关注的详细信息 Authentication in the Backend.