-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Basic authentication for remote feeds.
- Loading branch information
Showing
6 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Linq; | ||
using NuGet; | ||
|
||
namespace ripple.Nuget | ||
{ | ||
public class NugetCredentialsProvider : ICredentialProvider | ||
{ | ||
private readonly Dictionary<string, ICredentials> _credentials = new Dictionary<string, ICredentials>(); | ||
private static readonly Lazy<NugetCredentialsProvider> lazy = new Lazy<NugetCredentialsProvider>(() => new NugetCredentialsProvider()); | ||
|
||
private NugetCredentialsProvider() {} | ||
|
||
public static NugetCredentialsProvider Instance { get { return lazy.Value; } } | ||
|
||
public void AddCredentials(string key, ICredentials credentials) | ||
{ | ||
_credentials.Add(key, credentials); | ||
} | ||
|
||
public ICredentials GetCredentials(Uri uri, IWebProxy proxy, CredentialType credentialType, bool retrying) | ||
{ | ||
return _credentials[uri.OriginalString]; | ||
} | ||
|
||
public bool TryGetCredentials(string uri, out ICredentials credentials) | ||
{ | ||
if (_credentials.ContainsKey(uri)) | ||
{ | ||
credentials = _credentials[uri]; | ||
return true; | ||
} | ||
credentials = null; | ||
return false; | ||
} | ||
|
||
public bool TryGetRootCredentials(string uri, out ICredentials credentials) | ||
{ | ||
var matchingRoot = | ||
_credentials.Keys | ||
.SingleOrDefault(credUrl => uri.StartsWith(credUrl, StringComparison.InvariantCultureIgnoreCase)); | ||
if (!String.IsNullOrEmpty(matchingRoot)) | ||
{ | ||
credentials = _credentials[matchingRoot]; | ||
return true; | ||
} | ||
credentials = null; | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters