C# Class Google.GData.Client.OAuthBase

The original OAuth code from http://eran.sandler.co.il/, hosted at http://oauth.net Modified only to change namespace. Written by Eran Sandler (http://eran.sandler.co.il) Edited by Claudio Cherubino and Alain Vongsouvanh
Show file Open project: moljac/MonoMobile.Google.GData Class Usage Examples

Public Properties

Property Type Description
OAuth2AccessCode string
OAuth2AccessToken string
OAuth2AccessType string
OAuth2ApprovalPrompt string
OAuth2ClientId string
OAuth2ClientSecret string
OAuth2ExpiresIn string
OAuth2GrantType string
OAuth2RedirectUri string
OAuth2RefreshToken string
OAuth2ResponseType string
OAuth2State string
OAuth2TokenType string
OAuthCallbackKey string
OAuthConsumerKeyKey string
OAuthConsumerSecretKey string
OAuthNonceKey string
OAuthParameterPrefix string
OAuthScopeKey string
OAuthSignatureKey string
OAuthSignatureMethodKey string
OAuthTimestampKey string
OAuthTokenKey string
OAuthTokenSecretKey string
OAuthVerifierKey string
OAuthVersion string
OAuthVersionKey string

Protected Properties

Property Type Description
unreservedChars string

Public Methods

Method Description
EncodingPerRFC3986 ( string value ) : string

All parameter names and values are escaped using the [RFC3986] percent-encoding (%xx) mechanism. Characters not in the unreserved character MUST be encoded. Characters in the unreserved character set MUST NOT be encoded. Hexadecimal characters in encodings MUST be upper case. Text names and values MUST be encoded as UTF-8 octets before percent-encoding them per [RFC3629]

GenerateNonce ( ) : string

Generate a nonce

GenerateOAuthSignature ( string consumerSecret, string tokenSecret ) : string

oauth_signature is set to the concatenated encoded values of the Consumer Secret and Token Secret, separated by a ‘&’ character (ASCII code 38), even if either secret is empty. The result MUST be encoded again.

GenerateOAuthSignatureEncoded ( string consumerSecret, string tokenSecret ) : string

oauth_signature is set to the concatenated encoded values of the Consumer Secret and Token Secret, separated by a ‘&’ character (ASCII code 38), even if either secret is empty. This version calls GenerateOAuthSignature and encodes the whole signature again The result MUST be encoded again.

GenerateSignature ( Uri url, string httpMethod, Google.GData.Client.OAuthParameters parameters ) : string

Generates a signature using the specified signatureMethod

GenerateSignature ( Uri url, string consumerKey, string consumerSecret, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce ) : string

Generates a signature using the HMAC-SHA1 algorithm

GenerateSignature ( Uri url, string consumerKey, string consumerSecret, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, string signatureMethod ) : string

Generates a signature using the specified signatureMethod

GenerateSignatureBase ( Uri url, string httpMethod, Google.GData.Client.OAuthParameters parameters ) : string

Generate the signature base that is used to produce the signature

GenerateSignatureBase ( Uri url, string consumerKey, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, string signatureType ) : string

Generate the signature base that is used to produce the signature

GenerateSignatureUsingHash ( string signatureBase, HashAlgorithm hash ) : string

Generate the signature value based on the given signature base and hash algorithm

GenerateTimeStamp ( ) : string

Generate the timestamp for the signature

GetExchangeAccessCodeRequestBody ( Google.GData.Client.OAuth2Parameters parameters ) : String

Generate the request body for exchanging an access code for an access token.

GetOAuth2AccessToken ( Google.GData.Client.OAuth2Parameters parameters, String requestBody ) : void

Send the request body to the OAuth 2.0 token endpoint to retrieve an access token. When successful, updates the OAuthParameter instance passed as parameter by setting AccessToken, RefreshToken and TokenExpiry.

GetQueryParameters ( string querystring ) : string>.SortedDictionary

Overloaded version of GetQueryParameters to work without a IDictionary parameter

GetQueryParameters ( string querystring, string>.IDictionary dict ) : string>.SortedDictionary

Internal function to parse query string parameters and merge them with an existing dictionary

GetRefreshAccessTokenRequestBody ( Google.GData.Client.OAuth2Parameters parameters ) : String

Generate the request body for refreshing an access token.

Protected Methods

Method Description
NormalizeRequestParameters ( string>.SortedDictionary parameters ) : string

Normalizes the request parameters according to the spec for the signature generation.

Private Methods

Method Description
ComputeHash ( HashAlgorithm hashAlgorithm, string data ) : string

Helper function to compute a hash value

Method Details

EncodingPerRFC3986() public static method

All parameter names and values are escaped using the [RFC3986] percent-encoding (%xx) mechanism. Characters not in the unreserved character MUST be encoded. Characters in the unreserved character set MUST NOT be encoded. Hexadecimal characters in encodings MUST be upper case. Text names and values MUST be encoded as UTF-8 octets before percent-encoding them per [RFC3629]
public static EncodingPerRFC3986 ( string value ) : string
value string The value to Url encode
return string

GenerateNonce() public static method

Generate a nonce
public static GenerateNonce ( ) : string
return string

GenerateOAuthSignature() public static method

oauth_signature is set to the concatenated encoded values of the Consumer Secret and Token Secret, separated by a ‘&’ character (ASCII code 38), even if either secret is empty. The result MUST be encoded again.
public static GenerateOAuthSignature ( string consumerSecret, string tokenSecret ) : string
consumerSecret string
tokenSecret string
return string

GenerateOAuthSignatureEncoded() public static method

oauth_signature is set to the concatenated encoded values of the Consumer Secret and Token Secret, separated by a ‘&’ character (ASCII code 38), even if either secret is empty. This version calls GenerateOAuthSignature and encodes the whole signature again The result MUST be encoded again.
public static GenerateOAuthSignatureEncoded ( string consumerSecret, string tokenSecret ) : string
consumerSecret string
tokenSecret string
return string

GenerateSignature() public static method

Generates a signature using the specified signatureMethod
public static GenerateSignature ( Uri url, string httpMethod, Google.GData.Client.OAuthParameters parameters ) : string
url System.Uri The full url that needs to be signed including its non OAuth url parameters
httpMethod string The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)
parameters Google.GData.Client.OAuthParameters The OAuth parameters
return string

GenerateSignature() public static method

Generates a signature using the HMAC-SHA1 algorithm
public static GenerateSignature ( Uri url, string consumerKey, string consumerSecret, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce ) : string
url System.Uri The full url that needs to be signed including its non OAuth url parameters
consumerKey string The consumer key
consumerSecret string The consumer seceret
token string The token, if available. If not available pass null or an empty string
tokenSecret string The token secret, if available. If not available pass null or an empty string
httpMethod string The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)
timeStamp string The OAuth timestamp. Must be a valid timestamp and equal or greater than /// timestamps used in previous requests
nonce string The OAuth nonce. A random string uniquely generated for each request
return string

GenerateSignature() public static method

Generates a signature using the specified signatureMethod
public static GenerateSignature ( Uri url, string consumerKey, string consumerSecret, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, string signatureMethod ) : string
url System.Uri The full url that needs to be signed including its non OAuth url parameters
consumerKey string The consumer key
consumerSecret string The consumer seceret
token string The token, if available. If not available pass null or an empty string
tokenSecret string The token secret, if available. If not available pass null or an empty string
httpMethod string The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)
timeStamp string The OAuth timestamp. Must be a valid timestamp and equal or greater than /// timestamps used in previous requests
nonce string The OAuth nonce. A random string uniquely generated for each request
signatureMethod string The type of signature to use
return string

GenerateSignatureBase() public static method

Generate the signature base that is used to produce the signature
public static GenerateSignatureBase ( Uri url, string httpMethod, Google.GData.Client.OAuthParameters parameters ) : string
url System.Uri The full url that needs to be signed including its non OAuth url parameters
httpMethod string The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)
parameters Google.GData.Client.OAuthParameters The OAuth parameters
return string

GenerateSignatureBase() public static method

Generate the signature base that is used to produce the signature
public static GenerateSignatureBase ( Uri url, string consumerKey, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, string signatureType ) : string
url System.Uri The full url that needs to be signed including its non OAuth url parameters
consumerKey string The consumer key
token string The token, if available. If not available pass null or an empty string
tokenSecret string The token secret, if available. If not available pass null or an empty string
httpMethod string The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)
timeStamp string The OAuth timestamp. Must be a valid timestamp and equal or greater than /// timestamps used in previous requests
nonce string The OAuth nonce. A random string uniquely generated for each request
signatureType string The signature type.
return string

GenerateSignatureUsingHash() public static method

Generate the signature value based on the given signature base and hash algorithm
public static GenerateSignatureUsingHash ( string signatureBase, HashAlgorithm hash ) : string
signatureBase string The signature based as produced by the GenerateSignatureBase method or by any other means
hash System.Security.Cryptography.HashAlgorithm The hash algorithm used to perform the hashing. If the hashing algorithm requires initialization or a key it should be set prior to calling this method
return string

GenerateTimeStamp() public static method

Generate the timestamp for the signature
public static GenerateTimeStamp ( ) : string
return string

GetExchangeAccessCodeRequestBody() public static method

Generate the request body for exchanging an access code for an access token.
public static GetExchangeAccessCodeRequestBody ( Google.GData.Client.OAuth2Parameters parameters ) : String
parameters Google.GData.Client.OAuth2Parameters The OAuth 2.0 parameters
return String

GetOAuth2AccessToken() public static method

Send the request body to the OAuth 2.0 token endpoint to retrieve an access token. When successful, updates the OAuthParameter instance passed as parameter by setting AccessToken, RefreshToken and TokenExpiry.
public static GetOAuth2AccessToken ( Google.GData.Client.OAuth2Parameters parameters, String requestBody ) : void
parameters Google.GData.Client.OAuth2Parameters The OAuth 2.0 parameters
requestBody String The request body to send
return void

GetQueryParameters() public static method

Overloaded version of GetQueryParameters to work without a IDictionary parameter
public static GetQueryParameters ( string querystring ) : string>.SortedDictionary
querystring string The query string part of the Url
return string>.SortedDictionary

GetQueryParameters() public static method

Internal function to parse query string parameters and merge them with an existing dictionary
public static GetQueryParameters ( string querystring, string>.IDictionary dict ) : string>.SortedDictionary
querystring string The query string part of the Url
dict string>.IDictionary The dictionary to be merged with the query string parameters
return string>.SortedDictionary

GetRefreshAccessTokenRequestBody() public static method

Generate the request body for refreshing an access token.
public static GetRefreshAccessTokenRequestBody ( Google.GData.Client.OAuth2Parameters parameters ) : String
parameters Google.GData.Client.OAuth2Parameters The OAuth 2.0 parameters
return String

NormalizeRequestParameters() protected static method

Normalizes the request parameters according to the spec for the signature generation.
protected static NormalizeRequestParameters ( string>.SortedDictionary parameters ) : string
parameters string>.SortedDictionary The sorted dictionary containing parameters
return string

Property Details

OAuth2AccessCode public static property

public static string OAuth2AccessCode
return string

OAuth2AccessToken public static property

public static string OAuth2AccessToken
return string

OAuth2AccessType public static property

public static string OAuth2AccessType
return string

OAuth2ApprovalPrompt public static property

public static string OAuth2ApprovalPrompt
return string

OAuth2ClientId public static property

public static string OAuth2ClientId
return string

OAuth2ClientSecret public static property

public static string OAuth2ClientSecret
return string

OAuth2ExpiresIn public static property

public static string OAuth2ExpiresIn
return string

OAuth2GrantType public static property

public static string OAuth2GrantType
return string

OAuth2RedirectUri public static property

public static string OAuth2RedirectUri
return string

OAuth2RefreshToken public static property

public static string OAuth2RefreshToken
return string

OAuth2ResponseType public static property

public static string OAuth2ResponseType
return string

OAuth2State public static property

public static string OAuth2State
return string

OAuth2TokenType public static property

public static string OAuth2TokenType
return string

OAuthCallbackKey public static property

public static string OAuthCallbackKey
return string

OAuthConsumerKeyKey public static property

public static string OAuthConsumerKeyKey
return string

OAuthConsumerSecretKey public static property

public static string OAuthConsumerSecretKey
return string

OAuthNonceKey public static property

public static string OAuthNonceKey
return string

OAuthParameterPrefix public static property

public static string OAuthParameterPrefix
return string

OAuthScopeKey public static property

public static string OAuthScopeKey
return string

OAuthSignatureKey public static property

public static string OAuthSignatureKey
return string

OAuthSignatureMethodKey public static property

public static string OAuthSignatureMethodKey
return string

OAuthTimestampKey public static property

public static string OAuthTimestampKey
return string

OAuthTokenKey public static property

public static string OAuthTokenKey
return string

OAuthTokenSecretKey public static property

public static string OAuthTokenSecretKey
return string

OAuthVerifierKey public static property

public static string OAuthVerifierKey
return string

OAuthVersion public static property

public static string OAuthVersion
return string

OAuthVersionKey public static property

public static string OAuthVersionKey
return string

unreservedChars protected static property

protected static string unreservedChars
return string