Skip to content

Commit

Permalink
Merge pull request #128 from adamdruppe/master
Browse files Browse the repository at this point in the history
add support for oauth2 authentication MS Office uses
  • Loading branch information
adamdruppe authored Nov 30, 2023
2 parents 5c1df1c + 1e4ec6c commit 5bc2662
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions source/symmetry/imap/defines.d
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ enum Capability {
@("IDLE")
idle = 0x10,

@("AUTH=XOAUTH2")
oauth2,

@("IMAP4rev1")
imap4Rev1,

Expand Down
10 changes: 9 additions & 1 deletion source/symmetry/imap/request.d
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,15 @@ Session login(Session session) {
if (rg.status == ImapStatus.preAuth) {
rl = ImapStatus.preAuth;
} else {
if (session.capabilities.has(Capability.cramMD5) && session.options.cramMD5) {
if (session.capabilities.has(Capability.oauth2) && login.oauthToken.strip.length) {
version (Trace) stderr.writefln("oauth");
import std.base64;
auto str = Base64.encode(cast(ubyte[]) ("user=" ~ login.username ~ "\x01auth=Bearer " ~ login.oauthToken.strip ~ "\x01\x01"));
t = session.check!sendRequest(format!"AUTHENTICATE XOAUTH2 %s"(str));
res = session.check!responseGeneric(t);
version (Trace) stderr.writefln("response: %s", res);
rl = res.status;
} else if (session.capabilities.has(Capability.cramMD5) && session.options.cramMD5) {
version (Trace) stderr.writefln("cram");
t = session.check!sendRequest("AUTHENTICATE CRAM-MD5");
res = session.check!responseAuthenticate(t);
Expand Down
3 changes: 3 additions & 0 deletions source/symmetry/imap/session.d
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ struct ImapLogin {
@SILdoc("User's secret keyword. If a password wasn't supplied the user will be asked to enter one interactively the first time it will be needed. It takes a string as a value.")
string password;

@SILdoc("OAuth2 token, if present, it will try this before the username and password.")
string oauthToken;

string toString() const {
import std.format : format;
return format!"%s:[hidden]"(username);
Expand Down

0 comments on commit 5bc2662

Please sign in to comment.