本文整理汇总了C#中CredentialCache类的典型用法代码示例。如果您正苦于以下问题:C# CredentialCache类的具体用法?C# CredentialCache怎么用?C# CredentialCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CredentialCache类属于命名空间,在下文中一共展示了CredentialCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StoresCredentialForKeyAndGitKey
public async Task StoresCredentialForKeyAndGitKey()
{
using (var credentialCache = new CredentialCache())
{
try
{
var credential = Tuple.Create("somebody", "somebody's secret");
await credentialCache.InsertObject(nameof(StoresCredentialForKeyAndGitKey), credential);
var retrieved = await credentialCache.GetObject<Tuple<string, string>>(nameof(StoresCredentialForKeyAndGitKey));
Assert.Equal("somebody", retrieved.Item1);
Assert.Equal("somebody's secret", retrieved.Item2);
var retrieved2 = await credentialCache.GetObject<Tuple<string, string>>("git:" + nameof(StoresCredentialForKeyAndGitKey));
Assert.Equal("somebody", retrieved2.Item1);
Assert.Equal("somebody's secret", retrieved2.Item2);
}
finally
{
try
{
await credentialCache.Invalidate(nameof(StoresCredentialForKeyAndGitKey));
}
catch (Exception)
{
}
}
}
}
示例2: RetrievesValueWithAlternateKeys
public async Task RetrievesValueWithAlternateKeys()
{
const string key = nameof(RetrievesValueWithAlternateKeys);
using (var credentialCache = new CredentialCache())
{
try
{
var credential = Tuple.Create("somebody", "somebody's secret");
await credentialCache.InsertObject(key, credential);
var retrieved = await credentialCache.GetObject<Tuple<string, string>>(key);
Assert.Equal("somebody", retrieved.Item1);
Assert.Equal("somebody's secret", retrieved.Item2);
var retrieved2 = await credentialCache.GetObject<Tuple<string, string>>("git:" + key + "/");
Assert.Equal("somebody", retrieved2.Item1);
Assert.Equal("somebody's secret", retrieved2.Item2);
var retrieved3 = await credentialCache.GetObject<Tuple<string, string>>("login:" + key + "/");
Assert.Equal("somebody", retrieved3.Item1);
Assert.Equal("somebody's secret", retrieved3.Item2);
}
finally
{
await credentialCache.Invalidate(key);
}
}
}
示例3: OneDriveClient
/// <summary>
/// Instantiates a new OneDriveClient.
/// </summary>
public OneDriveClient(
AppConfig appConfig,
CredentialCache credentialCache = null,
IHttpProvider httpProvider = null,
IServiceInfoProvider serviceInfoProvider = null)
: base(appConfig, credentialCache, httpProvider, serviceInfoProvider)
{
}
示例4: ThrowsObservableInvalidOperationExceptionWhenRetrievingSomethingNotATuple
public async Task ThrowsObservableInvalidOperationExceptionWhenRetrievingSomethingNotATuple()
{
using (var credentialCache = new CredentialCache())
{
await Assert.ThrowsAsync<InvalidOperationException>(
async () => await credentialCache.GetObject<string>("_"));
}
}
示例5: OneDriveClient
/// <summary>
/// Instantiates a new OneDriveClient.
/// </summary>
public OneDriveClient(
AppConfig appConfig,
CredentialCache credentialCache = null,
IHttpProvider httpProvider = null,
IServiceInfoProvider serviceInfoProvider = null,
ClientType clientType = ClientType.Consumer)
: base(appConfig, credentialCache, httpProvider, serviceInfoProvider, clientType)
{
}
示例6: GetCredential
private static CredentialCache GetCredential()
{
string url = @"http://github.com/api/v3/users";
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
CredentialCache credentialCache = new CredentialCache();
//credentialCache.Add(new System.Uri(url), "Basic", new NetworkCredential(ConfigurationManager.AppSettings["gitHubUser"], ConfigurationManager.AppSettings["gitHubUserPassword"]));
credentialCache.Add(new System.Uri(url), "Basic", new NetworkCredential("huj", "Savit5ch"));
return credentialCache;
}
示例7: ThrowsObjectDisposedExceptionWhenDisposed
public async Task ThrowsObjectDisposedExceptionWhenDisposed()
{
using (var credentialCache = new CredentialCache())
{
credentialCache.Dispose();
await Assert.ThrowsAsync<ObjectDisposedException>(
async () => await credentialCache.GetObject<Tuple<string, string>>("_"));
}
}
示例8: UriAuthenticationTypeCredentialCache
private static CredentialCache UriAuthenticationTypeCredentialCache()
{
CredentialCache cc = new CredentialCache();
cc.Add(uriPrefix1, authenticationType1, credential1);
cc.Add(uriPrefix1, authenticationType2, credential2);
cc.Add(uriPrefix2, authenticationType1, credential3);
cc.Add(uriPrefix2, authenticationType2, credential4);
return cc;
}
示例9: CreateUriCredentialCacheCount
private static CredentialCacheCount CreateUriCredentialCacheCount(CredentialCache cc = null, int count = 0)
{
cc = cc ?? new CredentialCache();
cc.Add(uriPrefix1, authenticationType1, credential1); count++;
cc.Add(uriPrefix1, authenticationType2, credential2); count++;
cc.Add(uriPrefix2, authenticationType1, credential3); count++;
cc.Add(uriPrefix2, authenticationType2, credential4); count++;
return new CredentialCacheCount(cc, count);
}
示例10: TestRoundTrip
public void TestRoundTrip()
{
var credentials = new CredentialCache { Logon = "user", Password = "password", AccessToken = string.Empty };
var cache = credentials.ToString();
Assert.That(cache, Is.Not.Null);
Assert.That(cache, Does.Contain("user"));
Assert.That(cache, Does.Not.Contain("password"));
var parsed = CredentialCache.FromString(cache);
Assert.That(parsed, Is.Not.Null);
Assert.That(parsed.Logon, Is.EqualTo("user"));
Assert.That(parsed.Password, Is.EqualTo("password"));
Assert.That(parsed.AccessToken, Is.EqualTo(string.Empty));
}
示例11: GetServiceInfo
public Task<ServiceInfo> GetServiceInfo(AppConfig appConfig, CredentialCache credentialCache, IHttpProvider httpProvider)
{
var microsoftAccountServiceInfo = new MicrosoftAccountServiceInfo
{
AppId = appConfig.MicrosoftAccountAppId,
ClientSecret = appConfig.MicrosoftAccountClientSecret,
CredentialCache = credentialCache,
HttpProvider = httpProvider,
Scopes = appConfig.MicrosoftAccountScopes,
};
microsoftAccountServiceInfo.AuthenticationProvider = this.AuthenticationProvider ?? new OnlineIdAuthenticationProvider(microsoftAccountServiceInfo);
return Task.FromResult<ServiceInfo>(microsoftAccountServiceInfo);
}
示例12: GetServiceInfo
public Task<ServiceInfo> GetServiceInfo(AppConfig appConfig, CredentialCache credentialCache, IHttpProvider httpProvider)
{
var microsoftAccountServiceInfo = new MicrosoftAccountServiceInfo
{
AppId = appConfig.MicrosoftAccountAppId,
ClientSecret = appConfig.MicrosoftAccountClientSecret,
CredentialCache = credentialCache,
HttpProvider = httpProvider,
ReturnUrl = WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString(),
Scopes = appConfig.MicrosoftAccountScopes,
WebAuthenticationUi = this.webAuthenticationUi,
};
microsoftAccountServiceInfo.AuthenticationProvider = this.AuthenticationProvider ?? new WebAuthenticationBrokerAuthenticationProvider(microsoftAccountServiceInfo);
return Task.FromResult<ServiceInfo>(microsoftAccountServiceInfo);
}
示例13: CreateHostPortCredentialCacheCount
private static CredentialCacheCount CreateHostPortCredentialCacheCount(CredentialCache cc = null, int count = 0)
{
cc = cc ?? new CredentialCache();
cc.Add(host1, port1, authenticationType1, credential1); count++;
cc.Add(host1, port1, authenticationType2, credential2); count++;
cc.Add(host1, port2, authenticationType1, credential3); count++;
cc.Add(host1, port2, authenticationType2, credential4); count++;
cc.Add(host2, port1, authenticationType1, credential5); count++;
cc.Add(host2, port1, authenticationType2, credential6); count++;
cc.Add(host2, port2, authenticationType1, credential7); count++;
cc.Add(host2, port2, authenticationType2, credential8); count++;
return new CredentialCacheCount(cc, count);
}
示例14: HostPortAuthenticationTypeCredentialCache
private static CredentialCache HostPortAuthenticationTypeCredentialCache()
{
CredentialCache cc = new CredentialCache();
cc.Add(host1, port1, authenticationType1, credential1);
cc.Add(host1, port1, authenticationType2, credential2);
cc.Add(host1, port2, authenticationType1, credential3);
cc.Add(host1, port2, authenticationType2, credential4);
cc.Add(host2, port1, authenticationType1, credential5);
cc.Add(host2, port1, authenticationType2, credential6);
cc.Add(host2, port2, authenticationType1, credential7);
cc.Add(host2, port2, authenticationType2, credential8);
return cc;
}
示例15: GetMicrosoftAccountClient
/// <summary>
/// Creates a OneDrive client for use against OneDrive consumer.
/// </summary>
/// <param name="appId">The application ID for Microsoft Account authentication.</param>
/// <param name="returnUrl">The application return URL for Microsoft Account authentication.</param>
/// <param name="scopes">The requested scopes for Microsoft Account authentication.</param>
/// <param name="credentialCache">The cache instance for storing user credentials.</param>
/// <param name="httpProvider">The <see cref="IHttpProvider"/> for sending HTTP requests.</param>
/// <param name="webAuthenticationUi">The <see cref="IWebAuthenticationUi"/> for displaying authentication UI to the user.</param>
/// <returns>The <see cref="IOneDriveClient"/> for the session.</returns>
public static IOneDriveClient GetMicrosoftAccountClient(
string appId,
string returnUrl,
string[] scopes,
CredentialCache credentialCache = null,
IHttpProvider httpProvider = null,
IWebAuthenticationUi webAuthenticationUi = null)
{
return OneDriveClient.GetMicrosoftAccountClient(
appId,
returnUrl,
scopes,
/* clientSecret */ null,
credentialCache,
httpProvider,
new ServiceInfoProvider(webAuthenticationUi));
}