OAuth Class |
Namespace: MailBee
The OAuth type exposes the following members.
Name | Description | |
---|---|---|
AccessToken(String, String) |
Fetches Request Access from the specified URI
| |
AccessToken(String, String, StringDictionary) |
Fetches Request Access from the specified URI passing extra parameters in that URI.
| |
AuthorizeToken(String) |
Fetches Request Authorize from the specified URI (URL).
| |
AuthorizeToken(String, StringDictionary) |
Fetches Request Authorize from the specified URI passing extra parameters in that URI.
| |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
GetXOAuthKey(String) |
Fetches XOAuth key from the specified URI.
| |
GetXOAuthKey(String, StringDictionary) |
Fetches XOAuth key from the specified URI passing extra parameters in that URI.
| |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
RequestToken(String) |
Fetches Request Token from the specified URI.
| |
RequestToken(String, StringDictionary) |
Fetches Request Token from the specified URI passing extra parameters in that URI.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
OAuthCallbackKey |
The parameter name for setting callback URI.
|
Name | Description | |
---|---|---|
EnableOpenIDHybrid |
Enables or disables OpenID + OAuth mode.
| |
Token |
Gets token key from OAuth provider.
| |
TokenSecret |
Gets token secret key from OAuth provider.
|
Examples section contains several samples of using 2-legged and 3-legged OAuth with GMail IMAP and SMTP.
The first sample authenticates client in Gmail IMAP via 2-legged OAuth.
using System; using System.Collections.Specialized; using MailBee; using MailBee.ImapMail; class Sample { static void Main(string[] args) { string consumerKey = ""; string consumerSecret = ""; string userEmail = "e-mail@gmail.com"; OAuth myOAuth = new OAuth(consumerKey, consumerSecret); StringDictionary parameters = new StringDictionary(); parameters.Add("xoauth_requestor_id", userEmail); // Get XOAuth key for IMAP. string imapXOAuthKey = myOAuth.GetXOAuthKey( string.Format("https://mail.google.com/mail/b/{0}/imap/", userEmail)); // Last: Login to Gmail IMAP server using XOAuth. Imap imp = new Imap(); // Connect to the server, login and select inbox. imp.Connect("imap.gmail.com", 993); imp.Login(null, imapXOAuthKey, AuthenticationMethods.SaslOAuth, AuthenticationOptions.None, null); imp.SelectFolder("INBOX"); // Processing of INBOX emails here. //... imp.Disconnect(); } }
using System; using System.Collections.Specialized; using MailBee; using MailBee.ImapMail; class Sample { static void Main(string[] args) { Console.Write("Please enter your email: "); string userEmail = Console.ReadLine().Trim(); OAuth myOAuth = new OAuth("anonymous", "anonymous"); StringDictionary parameters = new StringDictionary(); parameters.Add("scope", "https://mail.google.com/"); parameters.Add(OAuth.OAuthCallbackKey, "oob"); // First: Fetch Request Token myOAuth.RequestToken("https://www.google.com/accounts/OAuthGetRequestToken", parameters); // Second: Redirect to Authorization and Fire up the browser System.Diagnostics.Process.Start( myOAuth.AuthorizeToken("https://www.google.com/accounts/OAuthAuthorizeToken")); Console.Write("Please enter the key: "); string key = Console.ReadLine().Trim(); // Third: Fetch Access Token myOAuth.AccessToken("https://www.google.com/accounts/OAuthGetAccessToken", key); // Get XOAuth key for IMAP. string imapXOAuthKey = myOAuth.GetXOAuthKey( string.Format("https://mail.google.com/mail/b/{0}/imap/", userEmail)); // Last: Login to Gmail IMAP server using XOAuth. Imap imp = new Imap(); // Connect to the server, login and select inbox. imp.Connect("imap.gmail.com", 993); imp.Login(null, imapXOAuthKey, AuthenticationMethods.SaslOAuth, AuthenticationOptions.None, null); imp.SelectFolder("INBOX"); // Processing of INBOX emails here. //... imp.Disconnect(); } }
using System; using System.Collections.Specialized; using MailBee; using MailBee.SmtpMail; class Sample { static void Main(string[] args) { Console.Write("Please enter your email: "); string userEmail = Console.ReadLine().Trim(); OAuth myOAuth = new OAuth("anonymous", "anonymous"); StringDictionary parameters = new StringDictionary(); parameters.Add("scope", "https://mail.google.com/"); parameters.Add(OAuth.OAuthCallbackKey, "oob"); // First: Fetch Request Token myOAuth.RequestToken("https://www.google.com/accounts/OAuthGetRequestToken", parameters); // Second: Redirect to Authorization and Fire up the browser System.Diagnostics.Process.Start( myOAuth.AuthorizeToken("https://www.google.com/accounts/OAuthAuthorizeToken")); Console.Write("Please enter the key: "); string key = Console.ReadLine().Trim(); // Third: Fetch Access Token myOAuth.AccessToken("https://www.google.com/accounts/OAuthGetAccessToken", key); // Get XOAuth key for IMAP. string smtpXOAuthKey = myOAuth.GetXOAuthKey( string.Format("https://mail.google.com/mail/b/{0}/smtp/", userEmail)); // Last: Login to Gmail SMTP server using XOAuth. // Connect to the server, login and send e-mail. SmtpServer server = new SmtpServer("smtp.gmail.com", 465, 0); server.AuthMethods = AuthenticationMethods.SaslOAuth; server.AccountName = null; server.Password = smtpXOAuthKey; Smtp mailer = new Smtp(); mailer.From.AsString = userEmail; mailer.To.Add("e-mail@host.com"); mailer.Subject = "My subject"; mailer.BodyPlainText = "Text body"; mailer.SmtpServers.Add(server); mailer.Send(); } }
using System; using System.Collections.Specialized; using MailBee; class Sample { static void Main(string[] args) { string consumerKey = ""; string consumerSecret = ""; Console.Write("Please enter your email: "); string userEmail = Console.ReadLine().Trim(); OAuth myOAuth = new OAuth(consumerKey, consumerSecret); StringDictionary parameters = new StringDictionary(); parameters.Add(OAuth.OAuthCallbackKey, "oob"); // First: Fetch Request Token myOAuth.RequestToken("https://api.login.yahoo.com/oauth/v2/get_request_token", parameters); // Second: Redirect to Authorization and Fire up the browser System.Diagnostics.Process.Start( myOAuth.AuthorizeToken("https://api.login.yahoo.com/oauth/v2/request_auth")); Console.Write("Please enter the key: "); string key = Console.ReadLine().Trim(); // Third: Fetch Access Token myOAuth.AccessToken("https://api.login.yahoo.com/oauth/v2/get_token", key); Console.WriteLine("Token: " + myOAuth.Token); Console.WriteLine("Token Secret: " + myOAuth.TokenSecret); Console.ReadLine(); } }