If you want to use this library in your desktop application, you must add an application configuration file (app.config) if not exist, and add configuration section in your configuration file:

<configSections>
  <section name="oauth.configuration" type="OAuth.OAuthConfigurationSection, OAuth"/>
</configSections>


And, add the following configuration:

<oauth.configuration defaultPersistProvider="XML">
  <providers>
    <add provider="GoogleAccount" 
             assembly="OAuth.Desktop" type="OAuth.Desktop.GoogleOAuthProvider" consumerKey="" consumerSecret="" 
             scope="https://www.google.com/base/feeds/ http://gdata.youtube.com/feeds/api/videos/" 
             consentUrl="https://www.google.com/accounts/OAuthAuthorizeToken" 
             requestTokenUrl="https://www.google.com/accounts/OAuthGetRequestToken" 
             requestAccessTokenUrl="https://www.google.com/accounts/OAuthGetAccessToken"/>
    <add provider="Yahoo" 
             assembly="OAuth.Desktop" type="OAuth.Desktop.YahooOAuthProvider" consumerKey="" consumerSecret="" 
             scope="" 
             consentUrl="https://api.login.yahoo.com/oauth/v2/request_auth" 
             requestTokenUrl="https://api.login.yahoo.com/oauth/v2/get_request_token" 
             requestAccessTokenUrl="https://api.login.yahoo.com/oauth/v2/get_token"/>
    <add provider="Twitter" 
             assembly="OAuth.Desktop" type="OAuth.Desktop.TwitterOAuthProvider" consumerKey="" consumerSecret="" 
             scope="" 
             consentUrl="http://api.twitter.com/oauth/authorize" 
             requestTokenUrl="https://api.twitter.com/oauth/request_token" 
             requestAccessTokenUrl="https://api.twitter.com/oauth/access_token"/>
    <add provider="Flickr" 
             assembly="OAuth.Desktop" type="OAuth.Desktop.FlickrOAuthProvider" consumerKey="" consumerSecret="" scope="" 
             consentUrl="" requestTokenUrl="" requestAccessTokenUrl=""/>
    <add provider="Facebook" 
             assembly="OAuth.Desktop" type="OAuth.Desktop.FacebookOAuthProvider" consumerKey="" consumerSecret="" 
             scope="publish_stream,read_stream,email,offline_access" 
             consentUrl="https://graph.facebook.com/oauth/authorize?client_id={0}&amp;redirect_uri=http://www.facebook.com/connect/login_success.html&amp;type=user_agent&amp;display=popup&amp;scope={1}" 
             requestTokenUrl="" requestAccessTokenUrl=""/>
  </providers>
  <persists>
    <add name="DB" provider="OAuth.PersistDBProvider" connectionString=""/>
    <add name="XML" provider="OAuth.PersistXmlProvider" connectionString=""/>
  </persists>
</oauth.configuration>


Fields Description:

1. consumerKey: The application key string assigned by OAuth Service Provider for your application.
2. consumerSecret: The application secret string assigned by OAuth Service Provider for your application.
3. scope: Scope definitions your application want to user to authorize, please see the documentation of OAuth Service Provider for details.
4. consentUrl: User authorization process URL provided by OAuth Service Provider, your must change it if service provider changes this URL.
5. requestTokenUrl: The URL for Application want to request an request token, provided by OAuth Service Provider, your must change it if service provider changes this URL.
6. requestAccessTokenUrl: The URL for Application want to obtain an access token, provided by OAuth Service Provider, your must change it if service provider changes this URL.

When your configuration completed, please add the following code:

OAuth.OAuthContext context = new OAuth.OAuthContext();


This code will use the first provider configuration to initialize OAuth Process.
Next, add the following code:

string userID = "1111";
if (!context.IsAccessTokenValid(userID))
{
    context.ObtainRequestToken();
    context.ObtainVerifier();
    context.ObtainAccessToken();
    context.PersistAccessToken(userID);
}
else
    context.LoadAccessToken(userID);


The OAuthContext will make OAuth process for first provider configuration to complete the OAuth Process, user will be prompted to login and authorize the scopes your application defined at configuration file.

More sample code, please download the source code, and view "OAuth.Desktop.Client" application's program.cs.

Last edited Apr 29, 2011 at 8:09 AM by regionbbs, version 1

Comments

No comments yet.