Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oauth2 not supported. #96

Open
jabberwocky-rs opened this issue Oct 28, 2022 · 3 comments
Open

Oauth2 not supported. #96

jabberwocky-rs opened this issue Oct 28, 2022 · 3 comments

Comments

@jabberwocky-rs
Copy link

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.

@apocsantos
Copy link

Hi,

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

Any example usage, please?

@stevenxi
Copy link

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.

@jstedfast
Copy link

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants