How to Authenticate with Rackspace API

In this example we will Authenicate with the Rackspace API, by making a Http Request in which you set the User and Key values for API access. The response will include the both the Server Management Url and the Auth Token in it headers. The Auth Token is valid for 24 hours.

using System;
using System.Net;

public class RackspaceSecurity
    private string _url;

    public RackspaceSecurity(string url)
        _url = url;

    public AuthInfo AuthenicationRequest(string user, string key)
            throw new ArgumentNullException("user");

        if (string.IsNullOrEmpty(key))
            throw new ArgumentNullException("key");

        WebRequest request = WebRequest.Create(_url);

        request.Headers["X-Auth-User"] = user;
        request.Headers["X-Auth-Key"] = key;

        AuthInfo info = new AuthInfo();

        using (var response = request.GetResponse())
            info.ServerManagementUrl = response.Headers["X-Server-Management-Url"];
            info.AuthToken = response.Headers["X-Auth-Token"];

        return info;

This is the class that is returned.

public class AuthInfo
    public string ServerManagementUrl;
    public string AuthToken;


No comments yet.

Add Yours

  • Author Avatar


Comment Arrow

About Author


Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning hands down.