A utility for handling authorization and request signatures for the OAuth protocol.
| C# | Visual Basic |
public static class OAuthUtility
Public NotInheritable Class OAuthUtility
| All Members | Methods | ||||
| Icon | Member | Description |
|---|---|---|
| AddOAuthEchoHeader(WebRequest, OAuthTokens) |
Adds the OAuth Echo header to the supplied web request.
| |
| BuildAuthorizationUri(String) |
Builds the authorization URI.
| |
| BuildAuthorizationUri(String, Boolean) |
Builds the authorization URI.
| |
| GetAccessToken(String, String, String, String) |
Gets the access token.
| |
| GetAccessToken(String, String, String, String, WebProxy) |
Gets the access token.
| |
| GetAccessTokenDuringCallback(String, String) |
Gets the access token during callback.
| |
| GetRequestToken(String, String, String) |
Gets the request token.
| |
| GetRequestToken(String, String, String, WebProxy) |
Gets a new OAuth request token from the twitter api.
|
Before you begin, you will need to register your application with Twitter.
To authenticate a user, there are 3 steps you will take:
1) Obtain a Request Token
2) Authentication
3) Obtain an Access Token
First, you must obtain a request token from the API.
CopyC#
CopyVB.NET
After the user has returned, you must obtain or reuse the request token and obtain the verifier value. For web applications, both values will be provided on the querystring to the callback url as oauth_token and oauth_verifier, respectively. For desktop and mobile applications, the verifier will be a numeric PIN supplied to the user.
CopyC#
CopyVB.NET
string consumerKey = "XXX"; string consumerSecret = "XXX"; // Obtain a request token OAuthTokenResponse requestToken = OAuthUtility.GetRequestToken(consumerKey, consumerSecret); // Direct or instruct the user to the following address: Uri authorizationUri = OAuthUtility.BuildAuthorizationUri(requestToken.Token);
Dim consumerKey As String = "XXX" Dim consumerSecret As String = "XXX" '-- Obtain a request token Dim requestToken As OAuthTokenResponse = OAuthUtility.GetRequestToken(consumerKey, consumerSecret) '-- Direct or instruct the user to the following address: Dim authorizationUri As Uri = OAuthUtility.BuildAuthorizationUri(requestToken.Token)
string consumerKey = "XXX"; string consumerSecret = "XXX"; string requestToken = "XXX"; string verifier = "XXX"; // Obtain the access token for this user. OAuthTokenResponse accessToken = OAuthUtility.GetAccessToken(consumerKey, consumerSecret, requestToken, verifier); // TODO: Save the access token to a database, session, xml file, or whereever my user data is stored.
Dim consumerKey As String = "XXX" Dim consumerSecret As String = "XXX" Dim requestToken As String = "XXX" Dim verifier As String = "XXX" '-- Obtain the access token for this user. Dim accessToken As OAuthTokenResponse = OAuthUtility.GetAccessToken(consumerKey, consumerSecret, requestToken, verifier) '-- TODO: Save the access token to a database, session, xml file, or whereever my user data is stored.
| Object | |
| OAuthUtility | |
OAuthTokenResponse
[!:Twitterizer.OAuthUtility.GetRequestToken(string,string)]
GetAccessToken(String, String, String, String)
BuildAuthorizationUri(String)
[!:Twitterizer.OAuthUtility.GetRequestToken(string,string)]
GetAccessToken(String, String, String, String)
BuildAuthorizationUri(String)