Implement HTTP Basic Auth in your Marketplace App
Updated: February 12, 2014
HTTP Basic Authentication is one of two authentication protocols supported by the Marketplace. Since this authentication method requires storing the user’s name and password for all access, we recommend that you use HTTP Basic Authentication only when you are creating an application for your own use or a single account.
HTTP Basic Authentication uses a user id and password to authenticate a user and then grant or deny access to a protected resource. The Marketplace implementation of HTTP Basic Authentication ignores the user id and requires a valid Marketplace account key (for example, /Xroufd9KIlLkr4Mjf8afk). As you design your application you need to decide whether you will include the account key in the application code, which makes your account key vulnerable to anyone who has the application, or ask the user to enter it at run time, which is error prone given the length and complexity of the key.
The code to implement HTTP Basic Authentication is relatively short and simple. Before you get to the code you must do the following in your application code.
Ensure that your project includes System.Net and your service class or reference namespace.
Create a Uri instance from the service’s root URL.
To find the service root URL:
Click the My Data tab at the Marketplace home page.
Locate the dataset you need the root service URL to.
Scroll down and click the Details tab.
Include this URL in your application code.
- Click the My Data tab at the Marketplace home page.
Create an identifier of the type of the dataset’s container.
There are two ways to find the container name.
Open the Object Browser in Visual Studio.
Locate your service class or reference.
Double-click the class name to expand it.
Locate a type whose name ends with “Container”.
For example: ContosoSalesContainer.
https://datamarket.azure.com/data.ashx/contoso/sales/navigate your browser to
Find the EntityContainer tag. The value of the Name attribute is the service container name. Example:
- Open the Object Browser in Visual Studio.
There are just two steps to implement HTTP Basic Authentication.
Instantiate the context identifier.
Add the credentials to the context.
Note At this time the Marketplace ignores the USER_ID so you can use an empty string in its place. Do not skip this parameter.