Skip to content

Commit 2584904

Browse files
committed
added OAuth2 authentication (Imap4Client.LoginOAuth2)
1 parent a5d7fc9 commit 2584904

12 files changed

Lines changed: 351 additions & 66 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,4 @@ _UpgradeReport_Files/
109109
Backup*/
110110
UpgradeLog*.XML
111111
*.pubxml
112+
/.cr/personal/Navigation/Code Places.xml

Class Library/ActiveUp.Net.Common/Events.cs

Lines changed: 117 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ namespace ActiveUp.Net.Mail
2424
/// <summary>
2525
/// EventHandler to be used with the Authenticating event.
2626
/// </summary>
27-
public delegate void AuthenticatingEventHandler(object sender, AuthenticatingEventArgs e);
27+
public delegate void AuthenticatingEventHandler(object sender, AuthenticatingEventArgsBase e);
2828
/// <summary>
2929
/// EventHandler to be used with the Authenticated event.
3030
/// </summary>
31-
public delegate void AuthenticatedEventHandler(object sender, AuthenticatedEventArgs e);
31+
public delegate void AuthenticatedEventHandler(object sender, AuthenticatedEventArgsBase e);
3232
/// <summary>
3333
/// EventHandler to be used with the Nooping event.
3434
/// </summary>
@@ -559,10 +559,49 @@ public string Response
559559
#if !PocketPC
560560
[System.Serializable]
561561
#endif
562-
public class AuthenticatedEventArgs : System.EventArgs
562+
563+
564+
public class AuthenticatedEventArgsBase : System.EventArgs
563565
{
564-
string _username,_password,_host,_serverResponse;
566+
protected string _username, _password, _host, _serverResponse;
567+
/// <summary>
568+
/// The username used to authenticate the user.
569+
/// </summary>
565570

571+
public string Username
572+
{
573+
get
574+
{
575+
return _username;
576+
}
577+
}
578+
579+
/// <summary>
580+
/// The address of the remote server.
581+
/// </summary>
582+
public string Host
583+
{
584+
get
585+
{
586+
return _host;
587+
}
588+
}
589+
590+
/// <summary>
591+
/// The server's response
592+
/// </summary>
593+
public string ServerResponse
594+
{
595+
get
596+
{
597+
return _serverResponse;
598+
}
599+
}
600+
}
601+
602+
public class AuthenticatedEventArgs : AuthenticatedEventArgsBase
603+
{
604+
566605
/// <summary>
567606
/// Constructor.
568607
/// </summary>
@@ -591,56 +630,84 @@ public AuthenticatedEventArgs(string username, string password, string serverRes
591630
_serverResponse = serverResponse;
592631
}
593632
/// <summary>
594-
/// The username used to authenticate the user.
633+
/// The password used to authenticate the user.
595634
/// </summary>
596-
public string Username
635+
public string Password
597636
{
598637
get
599638
{
600-
return _username;
639+
return _password;
601640
}
602641
}
642+
643+
}
644+
645+
public class AuthenticatedOAuth2EventArgs : AuthenticatedEventArgsBase
646+
{
603647
/// <summary>
604-
/// The password used to authenticate the user.
648+
/// Constructor.
605649
/// </summary>
606-
public string Password
650+
/// <param name="username">Username used to authenticate the user.</param>
651+
/// <param name="host">Address of the remote server.</param>
652+
/// <param name="serverResponse">The server response to the PASS command.</param>
653+
public AuthenticatedOAuth2EventArgs(string username, string host, string serverResponse)
607654
{
608-
get
609-
{
610-
return _password;
611-
}
655+
_username = username;
656+
_host = host;
657+
_serverResponse = serverResponse;
612658
}
613659
/// <summary>
614-
/// The address of the remote server.
660+
/// Constructor.
615661
/// </summary>
616-
public string Host
662+
/// <param name="username">Username used to authenticate the user.</param>
663+
/// <param name="serverResponse">The server response to the PASS command.</param>
664+
public AuthenticatedOAuth2EventArgs(string username, string serverResponse)
665+
{
666+
_username = username;
667+
_host = "unknown";
668+
_serverResponse = serverResponse;
669+
}
670+
671+
}
672+
/// <summary>
673+
/// Represents a future authentication process.
674+
/// </summary>
675+
#if !PocketPC
676+
[System.Serializable]
677+
#endif
678+
679+
680+
public class AuthenticatingEventArgsBase : System.EventArgs
681+
{
682+
protected string _username, _host;
683+
684+
/// <summary>
685+
/// The username used to authenticate the user.
686+
/// </summary>
687+
public string Username
617688
{
618689
get
619690
{
620-
return _host;
691+
return _username;
621692
}
622693
}
694+
623695
/// <summary>
624-
/// The server's response
696+
/// The address of the remote server.
625697
/// </summary>
626-
public string ServerResponse
698+
public string Host
627699
{
628700
get
629701
{
630-
return _serverResponse;
702+
return _host;
631703
}
632704
}
705+
633706
}
634707

635-
/// <summary>
636-
/// Represents a future authentication process.
637-
/// </summary>
638-
#if !PocketPC
639-
[System.Serializable]
640-
#endif
641-
public class AuthenticatingEventArgs : System.EventArgs
708+
public class AuthenticatingEventArgs : AuthenticatingEventArgsBase
642709
{
643-
string _username,_password,_host;
710+
string _password;
644711

645712
/// <summary>
646713
/// Constructor.
@@ -665,37 +732,45 @@ public AuthenticatingEventArgs(string username, string password)
665732
_password = password;
666733
_host = "unkwown";
667734
}
735+
668736
/// <summary>
669-
/// The username used to authenticate the user.
737+
/// The password used to authenticate the user.
670738
/// </summary>
671-
public string Username
739+
public string Password
672740
{
673741
get
674742
{
675-
return _username;
743+
return _password;
676744
}
677745
}
746+
}
747+
748+
public class AuthenticatingOAuth2EventArgs : AuthenticatingEventArgsBase
749+
{
678750
/// <summary>
679-
/// The password used to authenticate the user.
751+
/// Constructor.
680752
/// </summary>
681-
public string Password
753+
/// <param name="username">Username used to authenticate the user.</param>
754+
/// <param name="token">Password used to authenticate the user.</param>
755+
/// <param name="host">Address of the remote server.</param>
756+
public AuthenticatingOAuth2EventArgs(string username, string host)
682757
{
683-
get
684-
{
685-
return _password;
686-
}
758+
_username = username;
759+
_host = host;
687760
}
761+
688762
/// <summary>
689-
/// The address of the remote server.
763+
/// Constructor.
690764
/// </summary>
691-
public string Host
765+
/// <param name="username">Username used to authenticate the user.</param>
766+
/// <param name="token">Password used to authenticate the user.</param>
767+
public AuthenticatingOAuth2EventArgs(string username)
692768
{
693-
get
694-
{
695-
return _host;
696-
}
769+
_username = username;
770+
_host = "unkwown";
697771
}
698772
}
773+
699774
/*/// <summary>
700775
/// EventArgs used by the ArticleRetrieved event.
701776
/// </summary>

Class Library/ActiveUp.Net.Imap4/ActiveUp.Net.Imap4.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,29 @@
9696
<Prefer32Bit>false</Prefer32Bit>
9797
</PropertyGroup>
9898
<ItemGroup>
99+
<Reference Include="Microsoft.CSharp" />
100+
<Reference Include="Microsoft.Identity.Client, Version=4.48.1.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae, processorArchitecture=MSIL">
101+
<HintPath>..\..\packages\Microsoft.Identity.Client.4.48.1\lib\net45\Microsoft.Identity.Client.dll</HintPath>
102+
</Reference>
103+
<Reference Include="Microsoft.IdentityModel.Abstractions, Version=6.22.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
104+
<HintPath>..\..\packages\Microsoft.IdentityModel.Abstractions.6.22.0\lib\net45\Microsoft.IdentityModel.Abstractions.dll</HintPath>
105+
</Reference>
106+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
107+
<HintPath>..\..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
108+
</Reference>
99109
<Reference Include="System" />
100110
<Reference Include="System.Data" />
111+
<Reference Include="System.Data.DataSetExtensions" />
112+
<Reference Include="System.Drawing" />
113+
<Reference Include="System.IdentityModel" />
114+
<Reference Include="System.Net.Http" />
115+
<Reference Include="System.Windows.Forms" />
101116
<Reference Include="System.Xml" />
117+
<Reference Include="System.Xml.Linq" />
102118
</ItemGroup>
103119
<ItemGroup>
104120
<Compile Include="CommandOptions.cs" />
121+
<Compile Include="ExceptionsExtensions.cs" />
105122
<Compile Include="Fetch.cs" />
106123
<Compile Include="Flag.cs" />
107124
<Compile Include="FlagCollection.cs" />
@@ -111,10 +128,12 @@
111128
<Compile Include="Mailbox.cs" />
112129
<Compile Include="MailboxCollection.cs" />
113130
<Compile Include="MailboxPermission.cs" />
131+
<Compile Include="OAuth2Token.cs" />
114132
<Compile Include="Properties\AssemblyInfo.cs" />
115133
</ItemGroup>
116134
<ItemGroup>
117135
<None Include="ActiveUp.Net.Imap4.snk" />
136+
<None Include="packages.config" />
118137
</ItemGroup>
119138
<ItemGroup>
120139
<ProjectReference Include="..\ActiveUp.Net.Common\ActiveUp.Net.Common.csproj">
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace ActiveUp.Net.Imap4
7+
{
8+
public static class ExceptionsExtensions
9+
{
10+
11+
public static string HideSensitiveData(this string message)
12+
{
13+
if (!string.IsNullOrEmpty(message))
14+
{
15+
var loginToken = "login";
16+
var idx = message.IndexOf(loginToken, StringComparison.InvariantCultureIgnoreCase);
17+
if (idx > 0)
18+
{
19+
message = message.Substring(0, idx + loginToken.Length);
20+
message += " *** SENSITIVE DATA *** ";
21+
}
22+
}
23+
return message;
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)