foens/hpop

Oauth2 not supported.

jabberwocky-rs opened this issue · 3 comments

Since Microsoft and Gmail are requiring Oauth2 authentication, it would make sense to allow that in this package. The user would be required to obtain the authentication token and pass it as the password. The following code works for office365:

	/// <summary>
	/// Authenticates a user towards the POP server using the Oauth2 commands
	/// </summary>
	/// <param name="username">The username</param>
	/// <param name="password">The Oauth2 token</param>
	/// <exception cref="PopServerException">If the server responded with -ERR</exception>
	private void AuthenticateUsingOauth2(string username, string password)
	{
		string auth = "user=" + username + "\u0001auth=Bearer " + password + "\u0001\u0001";
		string authToken = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(auth));
		SendCommand("AUTH XOAUTH2"); // + password);
		SendCommand(authToken);

		// Authentication was successful if no exceptions thrown before getting here
	}

I just added a new Oauth2 authentication type. Unfortunately, it looks like Gmail has a slightly different syntax, so you might need a separate type for it.

This is not a bug, but it would extend the usefulness of OpenPop as email security becomes tighter.

Hi,

Is this already commited ? Or should we add it to the code ?

Any example usage, please?

hi @apocsantos ,

Feel free to use my fork that includes this change: https://github.com/stevenxi/hpop
With nuget: https://www.nuget.org/packages/OpenPop.Core_UDIntelFork

But please be aware it's a .net standard 2.0 build.

You guys should switch to MailKit instead. Unlike OpenPOP.NET, MailKit is still actively maintained. It's also more robust and more featureful.

Note: MailKit is my own project, so I'm biased, but I'm pretty confident that you'll agree.

I have instructions on how to use this with: