Add support for XOAUTH2 and OAUTHBEARER auth mechanisms #256
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found SmtpServer while trying to get my team off of Papercut, since Papercut forces developers to write SMTP-facing code that supports cleartext and no authentication. SmtpServer met all of my needs, with the exception of OAUTHBEARER and XOAUTH2 authentication mechanisms.
This PR adds support for SASL XOAUTH2 and SASL OAUTHBEARER, since I need something that will respond positively to those login requests in a bench testing scenario.
I added support for XOAUTH2 and OAUTHBEARER by adding separate
BearerTokenAuthenticatorrelated authentication classes. There are many parallels to the existingPasswordAuthenticatorclasses, but ultimately I thought it would be beneficial to keep them separate in case someone wants to enable a server that supports bothAUTH PLAIN/LOGINandAUTH XOAUTH2/OAUTHBEARER.One part I was not entirely sure about is how to decode
AUTH LOGIN XOAUTH2withinSmtpParser. It seemed like I should have been able to callreader.TryMake(TryMakeTextOrNumber, out var text)to obtain a sequence from the buffer that had both a string and number in it, but tokenization appears to isolate text strings from number strings. If there's a more idiomatic way of fetching an alphanumeric string in this case, let me know and I'll update this PR.Here's a sample:
Client code (assuming MailKit)