OpenID Class

Note: This API is now obsolete.

This class provides methods for OpenID authentication process. It can be used with OAuth class for hybrid OpenID + OAuth authentication.
Inheritance Hierarchy
SystemObject
  MailBeeOpenID

Namespace: MailBee
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
Syntax
[ObsoleteAttribute("This class is now obsolete as OpenID technology itself.")]
public class OpenID

The OpenID type exposes the following members.

Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodStatic memberGetOpenIDServer
Gets OpenID server URI from OpenID URI string.
Public methodStatic memberGetParamsForGoogleOpenIdWithOAuth
Creates a collection with OpenID request parameters for Google OpenID + OAuth.
Public methodStatic memberGetParamsForYahooOpenIdWithOAuth
Creates a collection with OpenID requests for Yahoo OpenID + OAuth.
Public methodStatic memberGetRedirectURL
Gets the URL on an OpenID server where your web application should redirect the user's browser to.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks

OpenID + OAuth hybrid method makes it possible to access certain data (like e-mails) in the user account without requiring the user to enter their e-mail address and password, provided that the user is already logged into their account by other means.

For instance, if the user is logged in their Gmail account on that computer and the user accesses your web application, it can get access to the e-mails in that account if the user permits this. The user just needs to click a button (confirmation from Google to grant access to the user's data to your web application), it's not required to enter the login or password. Also, your application does not get access to your account's password, only to your account's data.

To make requests for approval, your application must be registered on the web site of a service provider. E.g. if you want to let users grant you with the access to their Gmail mailboxes, you'll need to register your application with Google, or with Yahoo in order to access Yahoo Mail accounts. In return, the service provider assigns you a consumer key and consumer secret you'll need to pass to the service each time you make a request for a user's data.

See "Federated Login for Google Account Users" on Google web site for additional information on how to register your site in Google.

Note Note
This class provides helper classes which support OpenID + OAuth implementations of Google and Yahoo. You can, however, add any other implementation which sets OpenID/OAuth parameters as required by your service provider. For that, create and populate parameters object in the samples below not using GetParamsForGoogleOpenIdWithOAuth or GetParamsForYahooOpenIdWithOAuth methods. Or, you can use these methods and then adjust the resulting object in case if the implementation you're working with is very close to Google or Yahoo (for instance, simply requires adding an extra parameter).
Examples

This topic contains samples for both Google (Gmail) and Yahoo below.

The first web sample authenticates client in Gmail IMAP via OpenID + OAuth authentication. It has two pages: "Default.aspx" and "WebForm1.aspx". User opens "Default.aspx" and is get redirected to OpenID server page on Google web site (where the user can grant access to their data to your application). Then, Google redirects the user's browser to "WebForm1.aspx" which actually accesses the user's e-mail account via IMAP.

"http://[yourhost]/hybrid/WebForm1.aspx" designates the URL of "WebForm1.aspx" page (so that Google would know where it should redirect the user after passing the authorization stage).

If user sets "Remember this approval" checkbox on Google authentication page, next time Google will not ask to allow site request for getting Gmail access rights and will get access by default. GMail XOAuth key also may be stored by application for logging in GMail without authentication process.

// Default.aspx.cs

// To use the code below, import the following namespaces at the top of your code.
using MailBee;

// The actual code (put it into a method of your class).

// Get OpenID server name.
string openIdSrv = OpenID.GetOpenIDServer("https://www.google.com/accounts/o8/id");

StringDictionary parameters = OpenID.GetParamsForGoogleOpenIdWithOAuth();

parameters["openid.return_to"] = "http://[yourhost]/hybrid/WebForm1.aspx";
parameters["openid.realm"] = "http://[yourhost]/hybrid/";
parameters["openid.oauth.consumer"] = "[consumer_key]";

Response.Redirect(OpenID.GetRedirectURL(openIdSrv, parameters));

// WebForm1.aspx.cs

// To use the code below, import the following namespaces at the top of your code.
using MailBee;
using MailBee.ImapMail;

// The actual code (put it into a method of your class).

// Input consumerKey/consumerSecret from Google here.
string consumerKey = "";
string consumerSecret = "";

OAuth myOAuth = new OAuth(consumerKey, consumerSecret);

// Enables OpenID + OAuth extension.
myOAuth.EnableOpenIDHybrid = true;

// Request OAuth access key from
myOAuth.AccessToken("https://www.google.com/accounts/OAuthGetAccessToken",
    Request.QueryString["openid.ext2.request_token"]);

Response.Write("<b>Access Token:</b> " + myOAuth.Token + "<br/>");
Response.Write("<b>Access Token Secret:</b> " + myOAuth.TokenSecret + "<br/><br/>");

string imapXOAuthKey = myOAuth.GetXOAuthKey(
    string.Format("https://mail.google.com/mail/b/{0}/imap/", Request.QueryString["openid.ext1.value.email"]));

Response.Write("<b>GMail XOAuth key:</b> " + imapXOAuthKey + "<br/><br/>");

// 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");

Response.Write("<b>Gmail connected successfully via OpenID+XOAuth</b>");

// Processing of INBOX emails here.
//...
imp.Disconnect();
Examples

This web sample authenticates the client in Yahoo via OpenID + OAuth authentication. It works in much the same way as Google/Gmail version but it does not include the last step of connecting via IMAP (currently, Yahoo only supports HTTP access for OpenID + OAuth, such as for accessing Yahoo web services, although this may change in the future).

See "Yahoo! OAuth Quick Start Guide" on Yahoo web site for additional information on how to register your site in Yahoo.

// Default.aspx.cs

// To use the code below, import the following namespaces at the top of your code.
using MailBee;

string openIdSrv = "https://open.login.yahooapis.com/openid/op/auth";

StringDictionary parameters = OpenID.GetParamsForYahooOpenIdWithOAuth();

parameters["openid.return_to"] = "http://[yourhost]/hybrid/WebForm1.aspx";
parameters["openid.realm"] = "http://[yourhost]/hybrid/";
parameters["openid.oauth.consumer"] = "[consumer_key]";

Response.Redirect(OpenID.GetRedirectURL(openIdSrv, parameters));

// WebForm1.aspx.cs

// To use the code below, import the following namespaces at the top of your code.
using MailBee;

// Input consumerKey/consumerSecret from Yahoo here.
string consumerKey = "";
string consumerSecret = "";

OAuth myOAuth = new OAuth(consumerKey, consumerSecret);

// Enables OpenID + OAuth extension.
myOAuth.EnableOpenIDHybrid = true;

myOAuth.AccessToken("https://api.login.yahoo.com/oauth/v2/get_token",
    Request.QueryString["openid.oauth.request_token"]);

Response.Write("<b>Access Token:</b> " + myOAuth.Token + "<br/>");
Response.Write("<b>Access Token Secret:</b> " + myOAuth.TokenSecret);
See Also