title: Authorizing a request sidebarTitle: Authorizing a request keywords: [“authorize request”, “OAuth authorization”, “request authorization”, “OAuth 1.0a authorization”, “authorize API request”] description: The purpose of this document is to show you how to modify HTTP requests for the purpose of sending authorized requests to the X API. All of X’s APIs are…---
Authorizing a request
The purpose of this document is to show you how to modify HTTP requests for the purpose of sending authorized requests to the X API. All of X’s APIs are based on the HTTP protocol. This means that any software you write which uses X’s APIs sends a series of structured messages to X’s servers. For example, a request to post the text “Hello Ladies + Gentlemen, a signed OAuth request!” as a Tweet will look something like this:
Nonce
The oauth_nonce parameter is a unique token your application should generate for each unique request. X will use this value to determine whether a request has been submitted multiple times. The value for this request was generated by base64 encoding 32 bytes of random data, and stripping out all non-word characters, but any approach which produces a relatively random alphanumeric string should be OK here.
Signature
The oauth_signature parameter contains a value which is generated by running all of the other request parameters and two secret values through a signing algorithm. The purpose of the signature is so that X can verify that the request has not been modified in transit, verify the application sending the request, and verify that the application has authorization to interact with the user’s account.
The process for calculating the oauth_signature for this request is described in Creating a signature.
Signature method
The oauth_signature_method used by X is HMAC-SHA1. This value should be used for any authorized request sent to X’s API.
Timestamp
The oauth_timestamp parameter indicates when the request was created. This value should be the number of seconds since the Unix epoch at the point the request is generated, and should be easily generated in most programming languages. X will reject requests which were created too far in the past, so it is important to keep the clock of the computer generating requests in sync with NTP.
Token
The oauth_token parameter typically represents a user’s permission to share access to their account with your application. There are a few authentication requests where this value is not passed or is a different form of token, but those are covered in detail in Obtaining access tokens. For most general-purpose requests, you will use what is referred to as an access token.
You can generate a valid access token for your account on the settings page for your X app on the Developer Console.
Version
The oauth_version parameter should always be 1.0 for any request sent to the X API.