Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the key in new Azure App service?

While using the classic Azure Mobile services, you used to get a key along with a URL for your Mobile Service app. This key was also used to explore the APIs on your backend site & was used as a password.

With new Azure App services all you need to instntiate the mobile service client is the URL like below

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

There is no key *a second parameter that was available with Azure Mobile services. What is now used as password to explore the APIs on the web?

like image 424
Supreet Avatar asked Jan 06 '16 10:01

Supreet


People also ask

Where do I find my Azure subscription key?

You can obtain access keys in the portal or through PowerShell, Azure CLI, or REST API. Sign in to the Azure portal. List the search services for your subscription. Select the service and on the Overview page, click Settings >Keys to view admin and query keys.

How to set an application key for Azure mobile app?

You can set an application key for your Azure Mobile App like Azure Mobile Services. 1. Open Application Settings on Azure Mobile Application 2. Scroll down to App Settings Add these two lines. 3. Then click Save

How do I Find my Azure access key?

You can obtain access keys in the portal or through PowerShell, Azure CLI, or REST API. Sign in to the Azure portal. List the search services for your subscription. Select the service and on the Overview page, click Settings > Keys to view admin and query keys.

What is the Azure API key used for?

This key was also used to explore the APIs on your backend site & was used as a password. With new Azure App services all you need to instntiate the mobile service client is the URL like below There is no key *a second parameter that was available with Azure Mobile services. What is now used as password to explore the APIs on the web?

What are key-values in Azure App configuration?

Azure App Configuration stores configuration data as key-values. Key-values are a simple and flexible representation of application settings used by developers. Keys serve as identifiers for key-values and are used to store and retrieve corresponding values.


2 Answers

Supreet,

With App Services/Mobile Apps, the application key is no longer used/required, that is why it is no longer available on the portal. You can instantiate the client with the above code and start consuming the service APIs without that information.

For authentication, please refer to this documentation: https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-windows-store-dotnet-get-started-users/

I hope this helps.

like image 67
Fabio Cavalcante Avatar answered Sep 21 '22 23:09

Fabio Cavalcante


You can implement Application Key for Azure Mobile App if you want.

You can set an application key for your Azure Mobile App like Azure Mobile Services.

1. Open Application Settings on Azure Mobile Application

2. Scroll down to App Settings Add these two lines.

| zumo-api-key | TYPE YOUR API KEY |

| MS_SkipVersionCheck | True |

3. Then click Save

4. Open App Service Editor

5. Create a file on your main folder wwwroot

6. Name your file as 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. Update your API script as,

[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"
  }
}

Do not forget to change permissions to "Anonymous"

6. Update your Table script as,

[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"
  }
}

Do not forget to change permissions to "Anonymous"

7. Done!

Do not forget to add header while calling Azure Mobile/Web App.

Also, you can see more from this repository on Github.

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

like image 44
thisisfatih Avatar answered Sep 22 '22 23:09

thisisfatih