C# Class OAuth.OAuthTools

A general purpose toolset for creating components of an OAuth request.
显示文件 Open project: FoxCubGames/oauth-apn Class Usage Examples

Public Methods

Method Description
ConcatenateRequestElements ( string method, string url, WebParameterCollection parameters ) : string

Creates a request elements concatentation value to send with a request. This is also known as the signature base.

ConstructRequestUrl ( Uri url ) : string

Creates a request URL suitable for making OAuth requests. Resulting URLs must exclude port 80 or port 443 when accompanied by HTTP and HTTPS, respectively. Resulting URLs must be lower case.

GetNonce ( ) : string

Generates a random 16-byte lowercase alphanumeric string.

GetSignature ( OAuthSignatureMethod signatureMethod, OAuthSignatureTreatment signatureTreatment, string signatureBase, string consumerSecret ) : string

Creates a signature value given a signature base and the consumer secret. This method is used when the token secret is currently unknown.

GetSignature ( OAuthSignatureMethod signatureMethod, OAuthSignatureTreatment signatureTreatment, string signatureBase, string consumerSecret, string tokenSecret ) : string

Creates a signature value given a signature base and the consumer secret and a known token secret.

GetSignature ( OAuthSignatureMethod signatureMethod, string signatureBase, string consumerSecret ) : string

Creates a signature value given a signature base and the consumer secret. This method is used when the token secret is currently unknown.

GetSignature ( OAuthSignatureMethod signatureMethod, string signatureBase, string consumerSecret, string tokenSecret ) : string

Creates a signature value given a signature base and the consumer secret and a known token secret.

GetTimestamp ( ) : string

Generates a timestamp based on the current elapsed seconds since '01/01/1970 0000 GMT"

GetTimestamp ( System.DateTime dateTime ) : string

Generates a timestamp based on the elapsed seconds of a given time since '01/01/1970 0000 GMT"

NormalizeRequestParameters ( WebParameterCollection parameters ) : string

Sorts a collection of key-value pairs by name, and then value if equal, concatenating them into a single string. This string should be encoded prior to, or after normalization is run.

SortParametersExcludingSignature ( WebParameterCollection parameters ) : WebParameterCollection

Sorts a WebParameterCollection by name, and then value if equal.

UrlEncodeRelaxed ( string value ) : string

URL encodes a string based on section 5.1 of the OAuth spec. Namely, percent encoding with [RFC3986], avoiding unreserved characters, upper-casing hexadecimal characters, and UTF-8 encoding for text value pairs.

UrlEncodeStrict ( string value ) : string

URL encodes a string based on section 5.1 of the OAuth spec. Namely, percent encoding with [RFC3986], avoiding unreserved characters, upper-casing hexadecimal characters, and UTF-8 encoding for text value pairs.

Private Methods

Method Description
Concatenate ( ICollection collection, string separator, string spacer ) : string
EqualsIgnoreCase ( string left, string right ) : bool
HashWith ( string input, HashAlgorithm algorithm ) : string
IsNullOrBlank ( string value ) : bool
OAuthTools ( ) : System
PercentEncode ( string s ) : string
ToUnixTime ( System.DateTime dateTime ) : long

Method Details

ConcatenateRequestElements() public static method

Creates a request elements concatentation value to send with a request. This is also known as the signature base.
public static ConcatenateRequestElements ( string method, string url, WebParameterCollection parameters ) : string
method string The request's HTTP method type
url string The request URL
parameters WebParameterCollection The request's parameters
return string

ConstructRequestUrl() public static method

Creates a request URL suitable for making OAuth requests. Resulting URLs must exclude port 80 or port 443 when accompanied by HTTP and HTTPS, respectively. Resulting URLs must be lower case.
public static ConstructRequestUrl ( Uri url ) : string
url System.Uri The original request URL
return string

GetNonce() public static method

Generates a random 16-byte lowercase alphanumeric string.
public static GetNonce ( ) : string
return string

GetSignature() public static method

Creates a signature value given a signature base and the consumer secret. This method is used when the token secret is currently unknown.
public static GetSignature ( OAuthSignatureMethod signatureMethod, OAuthSignatureTreatment signatureTreatment, string signatureBase, string consumerSecret ) : string
signatureMethod OAuthSignatureMethod The hashing method
signatureTreatment OAuthSignatureTreatment The treatment to use on a signature value
signatureBase string The signature base
consumerSecret string The consumer key
return string

GetSignature() public static method

Creates a signature value given a signature base and the consumer secret and a known token secret.
public static GetSignature ( OAuthSignatureMethod signatureMethod, OAuthSignatureTreatment signatureTreatment, string signatureBase, string consumerSecret, string tokenSecret ) : string
signatureMethod OAuthSignatureMethod The hashing method
signatureTreatment OAuthSignatureTreatment The treatment to use on a signature value
signatureBase string The signature base
consumerSecret string The consumer secret
tokenSecret string The token secret
return string

GetSignature() public static method

Creates a signature value given a signature base and the consumer secret. This method is used when the token secret is currently unknown.
public static GetSignature ( OAuthSignatureMethod signatureMethod, string signatureBase, string consumerSecret ) : string
signatureMethod OAuthSignatureMethod The hashing method
signatureBase string The signature base
consumerSecret string The consumer key
return string

GetSignature() public static method

Creates a signature value given a signature base and the consumer secret and a known token secret.
public static GetSignature ( OAuthSignatureMethod signatureMethod, string signatureBase, string consumerSecret, string tokenSecret ) : string
signatureMethod OAuthSignatureMethod The hashing method
signatureBase string The signature base
consumerSecret string The consumer secret
tokenSecret string The token secret
return string

GetTimestamp() public static method

Generates a timestamp based on the current elapsed seconds since '01/01/1970 0000 GMT"
public static GetTimestamp ( ) : string
return string

GetTimestamp() public static method

Generates a timestamp based on the elapsed seconds of a given time since '01/01/1970 0000 GMT"
public static GetTimestamp ( System.DateTime dateTime ) : string
dateTime System.DateTime A specified point in time.
return string

NormalizeRequestParameters() public static method

Sorts a collection of key-value pairs by name, and then value if equal, concatenating them into a single string. This string should be encoded prior to, or after normalization is run.
public static NormalizeRequestParameters ( WebParameterCollection parameters ) : string
parameters WebParameterCollection
return string

SortParametersExcludingSignature() public static method

Sorts a WebParameterCollection by name, and then value if equal.
public static SortParametersExcludingSignature ( WebParameterCollection parameters ) : WebParameterCollection
parameters WebParameterCollection A collection of parameters to sort
return WebParameterCollection

UrlEncodeRelaxed() public static method

URL encodes a string based on section 5.1 of the OAuth spec. Namely, percent encoding with [RFC3986], avoiding unreserved characters, upper-casing hexadecimal characters, and UTF-8 encoding for text value pairs.
public static UrlEncodeRelaxed ( string value ) : string
value string
return string

UrlEncodeStrict() public static method

URL encodes a string based on section 5.1 of the OAuth spec. Namely, percent encoding with [RFC3986], avoiding unreserved characters, upper-casing hexadecimal characters, and UTF-8 encoding for text value pairs.
public static UrlEncodeStrict ( string value ) : string
value string
return string