95 lines
2.5 KiB
C#
95 lines
2.5 KiB
C#
using System;
|
|
|
|
namespace System.Net
|
|
{
|
|
// Token: 0x020001FE RID: 510
|
|
internal class BasicClient : IAuthenticationModule
|
|
{
|
|
// Token: 0x0600114D RID: 4429 RVA: 0x00032714 File Offset: 0x00030914
|
|
public Authorization Authenticate(string challenge, WebRequest webRequest, ICredentials credentials)
|
|
{
|
|
if (credentials == null || challenge == null)
|
|
{
|
|
return null;
|
|
}
|
|
string text = challenge.Trim();
|
|
if (text.ToLower().IndexOf("basic") == -1)
|
|
{
|
|
return null;
|
|
}
|
|
return BasicClient.InternalAuthenticate(webRequest, credentials);
|
|
}
|
|
|
|
// Token: 0x0600114E RID: 4430 RVA: 0x00032758 File Offset: 0x00030958
|
|
private static byte[] GetBytes(string str)
|
|
{
|
|
int i = str.Length;
|
|
byte[] array = new byte[i];
|
|
for (i--; i >= 0; i--)
|
|
{
|
|
array[i] = (byte)str[i];
|
|
}
|
|
return array;
|
|
}
|
|
|
|
// Token: 0x0600114F RID: 4431 RVA: 0x00032794 File Offset: 0x00030994
|
|
private static Authorization InternalAuthenticate(WebRequest webRequest, ICredentials credentials)
|
|
{
|
|
HttpWebRequest httpWebRequest = webRequest as HttpWebRequest;
|
|
if (httpWebRequest == null || credentials == null)
|
|
{
|
|
return null;
|
|
}
|
|
NetworkCredential credential = credentials.GetCredential(httpWebRequest.AuthUri, "basic");
|
|
if (credential == null)
|
|
{
|
|
return null;
|
|
}
|
|
string userName = credential.UserName;
|
|
if (userName == null || userName == string.Empty)
|
|
{
|
|
return null;
|
|
}
|
|
string password = credential.Password;
|
|
string domain = credential.Domain;
|
|
byte[] array;
|
|
if (domain == null || domain == string.Empty || domain.Trim() == string.Empty)
|
|
{
|
|
array = BasicClient.GetBytes(userName + ":" + password);
|
|
}
|
|
else
|
|
{
|
|
array = BasicClient.GetBytes(string.Concat(new string[] { domain, "\\", userName, ":", password }));
|
|
}
|
|
string text = "Basic " + Convert.ToBase64String(array);
|
|
return new Authorization(text);
|
|
}
|
|
|
|
// Token: 0x06001150 RID: 4432 RVA: 0x00032890 File Offset: 0x00030A90
|
|
public Authorization PreAuthenticate(WebRequest webRequest, ICredentials credentials)
|
|
{
|
|
return BasicClient.InternalAuthenticate(webRequest, credentials);
|
|
}
|
|
|
|
// Token: 0x170005B3 RID: 1459
|
|
// (get) Token: 0x06001151 RID: 4433 RVA: 0x0003289C File Offset: 0x00030A9C
|
|
public string AuthenticationType
|
|
{
|
|
get
|
|
{
|
|
return "Basic";
|
|
}
|
|
}
|
|
|
|
// Token: 0x170005B4 RID: 1460
|
|
// (get) Token: 0x06001152 RID: 4434 RVA: 0x000328A4 File Offset: 0x00030AA4
|
|
public bool CanPreAuthenticate
|
|
{
|
|
get
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|