I have a library that provides a HttpHeaderModel
model - HttpHeaderService.cs with unit tests in HttpHeaderServiceTest.cs. These values are what can be used in the code that does the http request.
This can also be downloaded from Nuget as CarlPaton.Common
Basic Authentication
This is added to the Header
of the request in the format name
and value
. The name is Authorization
and the value is the word Basic
and a base 64 encoded string of username:password
. Example: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
1 | var auth = string.Format("{0}:{1}", "username", "password"); |
1 | var request = (HttpWebRequest)WebRequest.Create(url); |
OAuth1
OAuth1 is deprecated, please use OAuth 2.0
This is added to the Header
of the request in the format name
and value
. The name is Authorization
and the value is the word OAuth
followed by concatinated string of key/values oauth_consumer_key
, oauth_token
, oauth_signature_method
, oauth_timestamp
, oauth_nonce
, oauth_version
and oauth_signature
.
The oauth_signature
is simply the consumerSecret
& tokenSecret
joined by &
as url-encoding %26
Example:
1 | $"OAuth oauth_consumer_key=\"{consumerKey}\",oauth_token=\"{accessToken}\",oauth_signature_method=\"PLAINTEXT\",oauth_timestamp=\"{timeStamp}\",oauth_nonce=\"{nonce}\",oauth_version=\"1.0\",oauth_signature=\"{consumerSecret}%26{tokenSecret}\"" |
1 | var request = (HttpWebRequest)WebRequest.Create(url); |