Authenticate (dlbv3)

Whether you use cURL, a REST client, or a command-line client (CLI) to send requests to the Dedicated Load Balancer API, you need an authentication token to include in the X-Auth-Token header of each API request. You get a token by submitting an authentication request with valid account credentials to the following Rackspace Cloud Identity API service endpoint:

https://identity.api.rackspacecloud.com/v2.0

With a valid token, you can send API requests to any of the API service endpoints that you are authorized to use. The authentication response includes a token expiration date. When a token expires, you can send another authentication request to get a new one.

Note

For more information about authentication tokens, see the following topics in the Rackspace Cloud Identity developer documentation.

  • Authentication token operations
    The examples in the Getting Started Guide show how to authenticate by using username and API key credentials, which is a more secure way to communicate with API services. The authentication token operations reference describes other types of credentials that you can use for authentication, for example multi-factor authentication passcode.
  • Manage authentication tokens

Authenticate by using cURL

Follow these steps to authenticate to the Rackspace Cloud by using cURL:

Send an authentication request

From a command prompt, send a POST tokens request to the Rackspace Cloud Identity service. Include your API access username and API key as shown in the following example. Replace $APIAccessUserName with your API access username and $apiKey with your API key.

$ curl https://identity.api.rackspacecloud.com/v2.0/tokens \
       -X POST \
       -d '{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"$APIAccessUserName","apiKey":"$apiKey"}}}' \
       -H "Content-type: application/json" | python -m json.tool

Review the authentication response

If your credentials are valid, the Identity service returns an authentication response that includes the following information:

  • an authentication token
  • a service catalog with information about the services you can access.
  • user information and role assignments

Note

For detailed information about the authentication response, see the Annotated authentication request andresponse in the Rackspace Cloud API documentation.

In the following example, the ellipsis (…) represents other service endpoints that are not shown. The values shown in this and other examples vary because the information returned is specific to your account.

Example: Authentication response

{
 "access": {
  "serviceCatalog": [],
  "user": {
    "RAX-AUTH:defaultRegion": "",
    "id": "<username:string>",
    "name": "<username:string>",
    "roles": [
      {
        "name": "<role:string>"
      },
    ],
  },
  "token": {
    "expires": "2016-07-13T03:57:39.236Z",
    "RAX-AUTH:authenticatedBy": [
      "PASSWORD"
    ],
    "id": "<auth-token:string>"
    }
  }
}

If the request was successful, it returns the following values that you need to include when you make service requests to the Rackspace product API:

token ID:

The token ID value is required to confirm your identity each time you access the service. Include it in the X-Auth-Token header for each API request.

The expires attribute indicates the date and time that the token will expire, unless it is revoked before the expiration. To get a new token, submit another authentication request. For more information, see Manage authentication tokens.

tenant ID:

The tenant ID provides your account number. For most Rackspace Cloud service APIs, the tenant ID is appended to the API endpoint in the service catalog automatically. For Rackspace Cloud services, the tenant ID has the same value as the tenant name.

endpoint:

The API endpoint provides the URL that you use to access the API service.

If the request failed, review the response message and the following error message descriptions to determine next steps:

  • If you see the following error message, review the authentication request for syntax or coding errors. If you are using cURL, see Using cURL.
    400 Invalid request body: unable to parse Auth data. Please review XML or
    JSON formatting
    
  • If you see the following error message, verify the authentication credentials submitted in the authentication request. If necessary, contact your Rackspace Cloud Administrator or Rackspace Support to get valid credentials.
    401 Unable to authenticate user with credentials provided.
    

Note

For additional information about authentication errors, see the Identity API Reference documentation.

Configure environment variables

To make it easier to include the token ID, endpoint, and other values in API requests, use the``export`` command to create environment variables that can be substituted for the actual values. For example, you can create an ENDPOINT variable to store the URL for accessing an API service. To reference the value in an API request, prefix the variable name with a $, for example $ENDPOINT.

Using environment variables

Note

The environment variables created with the export command are valid only for the current terminal session. If you start a new session, run the export commands again.

To reuse the variables across sessions, update the configuration file for your shell environment to include the export statements.

Create environment variables

  1. In the token section of the authentication response, copy the token id and value from the token object.

    {
      "access": {
        "token": {
          "id": "AA2345631l1NVdD6D1OCauKA0e9fioquZqVlS-hpbCqQ5Yx1zLOREGf4efBh10CfB5AvjC1yld4ZNJUouE7DA0QB0n5nRbdDsYADA-ORICIqHNqOVS_kYmedqDh75c_PLe123456789101",
          "expires": "2015-11-18T18:35:45.013Z"
          },
          "RAX-AUTH:authenticatedBy": [
            "APIKEY"
          ]
        },
      }
    }
    
  2. Export the token ID to an environment variable that can be supplied in the X-Auth-Token header required in each API request.

    export TOKEN="token-id"
    

    Replace token-id with the authentication token id value returned in the authentication response.

  3. Export the tenant ID to an environment variable that you can supply in requests that require you to specify a tenant ID.

    export TENANT="tenant-id"
    
  4. In the service catalog section of the authentication response, copy the publicURL value for the Dedicated Load Balancer API, version, and region that you want to access.

  5. Copy the URL and export it to an environment variable.

    export ENDPOINT="publicURL"
    

    Replace publicURL with the publicURL value listed in the service catalog.