Skip to content

Commit

Permalink
Updated IAuthentication interface to support more types of Authentica…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
ravibpatel committed Aug 24, 2020
1 parent e0480e2 commit cdcbc2d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
5 changes: 1 addition & 4 deletions AutoUpdater.NET/AutoUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,7 @@ internal static MyWebClient GetWebClient(Uri uri, IAuthentication basicAuthentic
}
else
{
if (basicAuthentication != null)
{
webClient.Headers[HttpRequestHeader.Authorization] = basicAuthentication.ToString();
}
basicAuthentication?.Apply(ref webClient);

webClient.Headers[HttpRequestHeader.UserAgent] = HttpUserAgent;
}
Expand Down
9 changes: 8 additions & 1 deletion AutoUpdater.NET/BasicAuthentication.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Text;

namespace AutoUpdaterDotNET
Expand All @@ -13,7 +14,7 @@ public class BasicAuthentication : IAuthentication
private string Password { get; }

/// <summary>
/// Initializes credentials for Basic Authentication.
/// Initializes credentials for Basic Authentication.
/// </summary>
/// <param name="username">Username to use for Basic Authentication</param>
/// <param name="password">Password to use for Basic Authentication</param>
Expand All @@ -29,5 +30,11 @@ public override string ToString()
var token = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{Username}:{Password}"));
return $"Basic {token}";
}

/// <inheritdoc />
public void Apply(ref MyWebClient webClient)
{
webClient.Headers[HttpRequestHeader.Authorization] = ToString();
}
}
}
14 changes: 9 additions & 5 deletions AutoUpdater.NET/CustomAuthentication.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace AutoUpdaterDotNET
{
Expand All @@ -12,18 +10,24 @@ public class CustomAuthentication : IAuthentication
private string HttpRequestHeaderAuthorizationValue { get; }

/// <summary>
/// Initializes authorization header value for Custom Authentication
/// Initializes authorization header value for Custom Authentication
/// </summary>
/// <param name="httpRequestHeaderAuthorizationValue">Value to use as http request header authorization value</param>
public CustomAuthentication(string httpRequestHeaderAuthorizationValue)
{
HttpRequestHeaderAuthorizationValue = httpRequestHeaderAuthorizationValue;
}

/// <inheritdoc />
public override string ToString()
{
return HttpRequestHeaderAuthorizationValue;
}

/// <inheritdoc />
public void Apply(ref MyWebClient webClient)
{
webClient.Headers[HttpRequestHeader.Authorization] = ToString();
}
}
}
5 changes: 5 additions & 0 deletions AutoUpdater.NET/IAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
/// </summary>
public interface IAuthentication
{
/// <summary>
/// Apply the authentication to webclient.
/// </summary>
/// <param name="webClient">WebClient for which you want to use this authentication method.</param>
void Apply(ref MyWebClient webClient);
}
}

0 comments on commit cdcbc2d

Please sign in to comment.