1. Putting ACS in place
Your first step in upgrading
the service is to support a simple scenario where customers will have a
shared secret (similar to a username and password) to access the
service. Whoever they give that secret to will be able to use the
service. They’ll be able to change the secret when they need to, just
like changing your password every 30 days.
Your first step is to
create an AppFabric namespace. This namespace is a lot like a container
in BLOB storage—it holds the settings for how you’re using the ACS
service. You could have several namespaces if you wanted to, perhaps to
isolate different services with different configurations.
To create the namespace, you’ll use the Azure portal, shown in figure 1. Besides creating the namespace, the portal doesn’t do much with regards to ACS. There are other tools for that.
To create a namespace, log in
to the Azure portal and choose AppFabric on the left side. You’ll then
see a list of your existing namespaces and a button for creating a new
one.
To create a new namespace, you simply need to provide a globally unique name for your namespace. In figure 1, you can see that we have selected StringReversalInc for our namespace. Once you click the Create button, AppFabric will provision its systems with your namespace.
As you can see in figure 2,
ACS has configured both a Service Bus and an ACS service for your
namespace. The service endpoints for both services will be displayed as
shown in the figure. Notice that the namespace is the hostname of the
service endpoints.
A
management key will be created for you as well. This 32-byte symmetric
key is what you’ll use when accessing the AppFabric management service
to perform operations on your namespace. We won’t explore the management
service in this chapter, but you should check it out. These keys should
not be shared outside your organization, or published in a book where
anyone can get ahold of them.
2. Reviewing the string-reversal service
For this chapter’s purposes, we’ll use a local REST version of the string-reversal service .
You can find the complete code for this revised service in the sample
code for this chapter. We’ve removed the entire worker role and
Azure-related code to do this. ACS is about securing REST-based
services, and our old service used a TCP-based binding. We’ve changed it
to use REST by using the WebServiceHost and the WebHttpBinding classes.
The following listing shows
how we’re building our simple little service. This code will start up
the service and wait for calls to the service.
Listing 1. A simple REST service
If
you run this sample string-reversal service, you can make all of the
requests to the service you want. The sample code includes a simple
client that will call the service.
The next few steps are going
to center around adding code to the service so that it can read and use
SWT tokens. Once that’s done, you can upgrade the client so it can fetch
a token from ACS and use it during a request to the service.