A Future Claims-Based Approach

Must Read

What Are the Pro’s and Con’s of Refinancing a Mortgage?

Over the last 10 years mortgage rates have consistently been at historically low levels. This resulted in a level...

Bad Credit Home Loan Refinancing – A Hope For People With Poor Credit

It is an undeniable fact that a person might face financial difficulties and need to look for financing for...

Federal Consolidation Student Loans – Difference Between Federal and Private Student Loans

The best tool for managing a few debts is the student loan consolidation. This helps you mix all your...

Qualifying For Student Loans in the Age of Stimulus Money

Student loans are loans offered to students to assist in payment of the costs of a professional education. If...

College Loan Interest Rates – What You Need to Know About Student Loans

Congratulations! You have made the decision to take your education to a higher level by attending college. This is...

Interest Rates for Home Equity Lines of Credit

Just what is a home equity loan and what are the home equity line of credit interest rates? They...

In the future, Tailspin is considering replacing the simple user name and password authentication scheme with a claims-based approach. One option is to use Simple Web Token (SWT) and the Open Authentication (OAuth) 2.0 protocol. This approach offers the following benefits:

  • The authentication process is managed externally from the Tailspin Surveys application.
  • The authentication process uses established standards.
  • The Surveys application can use a claims-based approach to handle any future authorization requirements.

Figure 2 illustrates this approach, showing the external token issuer.

An authentication approach using SWT for the Surveys web service

In this scenario, before the mobile client application invokes a Surveys web service, it must obtain an SWT. It does this by sending a request to a token issuer that can issue SWTs; for example, Windows Azure Access Control Services (ACS). The request includes the items of information described in the following table.

Windows Azure Access Control Services

The client ID and client secret enable the issuer to determine which application is requesting an SWT. The issuer uses the user name and password to authenticate the user.

The token issuer then constructs an SWT containing the user’s identity and any other claims that the consumer application (Tailspin Surveys) might require. The issuer also attaches a hash value generated using a secret key shared with the Tailspin Surveys service.

When the client application requests data from the Surveys service, it attaches the SWT to the request in the request’s authorization header.

When the Surveys service receives the request, a custom authentication module extracts the SWT from the authorization header, validates the SWT, and then extracts the claims from the SWT. The Surveys service can then use the claims with its authorization rules to determine what data, if any, it should return to the user.

The validation of the SWT in the custom authentication module performs the following steps.

  • It verifies the hash of the SWT by using the shared secret key. This enables the Surveys service to verify the data integrity and the authenticity of the message.
  • It verifies that the SWT has not expired. The token issuer sets the expiration time when it creates the SWT.
  • It checks that the issuer that created the SWT is an issuer that the service is configured to trust.
  • It checks that the client application that is making the request is a client that the service is configured to trust.

Inside the Implementation

Now is a good time to walk through the code that implements the authentication process in more detail. As you go through this section, you may want to download the Visual Studio solution for the Tailspin Surveys application from CodePlex (

The CustomServiceHostFactory class in the TailSpin.Services. Surveys project initializes the Surveys service. The following code example shows how this factory class creates the authorization manager.

public class CustomServiceHostFactory : WebServiceHostFactory
private readonly IUnityContainer container;
public CustomServiceHostFactory(IUnityContainer container)
this.container = container;
protected override ServiceHost CreateServiceHost(
Type serviceType, Uri[] baseAddresses)
var host = new CustomServiceHost(
serviceType, baseAddresses, this.container);
host.Authorization.ServiceAuthorizationManager =
new SimulatedWebServiceAuthorizationManager();
host.Authorization.PrincipalPermissionMode =
return host;


Note: The sample Surveys application uses a simulated authorization manager. You must replace this with a real authorization manager in a production application.


The following code example from the SimulatedWebServiceAuthorizationManager class shows how to override the CheckAccess- Core method in the ServiceAuthorizationManager class to provide a custom authorization decision.

protected override bool CheckAccessCore(
OperationContext operationContext)
if (WebOperationContext.Current != null)
var headers =
if (headers != null)
var authorizationHeader =
if (!string.IsNullOrEmpty(authorizationHeader))
if (authorizationHeader.StartsWith(“user”))
var userRegex = new Regex(@”(w+):([^s]+)”,
var username = userRegex.Match(authorizationHeader)
var password = userRegex.Match(authorizationHeader)
if (ValidateUserAndPassword(username, password))
var identity = new ClaimsIdentity(
new Claim(System.IdentityModel.Claims
.ClaimTypes.Name, username)
var principal =
.AuthorizationContext.Properties[“Principal”] =
return true;
catch (Exception)
if (WebOperationContext.Current != null)
WebOperationContext.Current.OutgoingResponse.StatusCode =
return false;
if (WebOperationContext.Current != null)
WebOperationContext.Current.OutgoingResponse.StatusCode =
return false;

In this simulated authorization manager class, the CheckAccess Core method extracts the user name and password from the authorization header, calls a validation routine, and if the validation routine  succeeds, it attaches a ClaimsPrincipal object to the web service context.

In the sample application, the validation routine does nothing more than check that the user name is one of several hard-coded values.

The following code example shows how the RequestTo method in the HttpClient class adds the authorization header with the user name and password credentials to the HTTP request that the mobile client sends to the various Tailspin web services.

public static HttpWebRequest RequestTo(
Uri surveysUri, string userName, string password)
var request = (HttpWebRequest)WebRequest.Create(surveysUri);
var authHeader = string.Format(CultureInfo.InvariantCulture,
“user {0}:{1}”, userName, password);
request.Headers[HttpRequestHeader.Authorization] = authHeader;
return request;


Latest News

Digital Marketing for Beginners

Digital marketing for starter, Let to basic learning about connecting with your audience in the right place at the...

More Articles Like This