本文整理汇总了C#中CredentialCache类的典型用法代码示例。如果您正苦于以下问题:C# CredentialCache类的具体用法?C# CredentialCache怎么用?C# CredentialCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CredentialCache类属于命名空间,在下文中一共展示了CredentialCache类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
{
}
}
}
}
开发者ID:kaustubhcs,项目名称:VisualStudio,代码行数:29,代码来源:CredentialCacheTests.cs
示例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);
}
}
}
开发者ID:kaustubhcs,项目名称:VisualStudio,代码行数:31,代码来源:CredentialCacheTests.cs
示例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)
{
}
开发者ID:nczsl,项目名称:onedrive-sdk-csharp,代码行数:11,代码来源:OneDriveClient.cs
示例4: ThrowsObservableInvalidOperationExceptionWhenRetrievingSomethingNotATuple
public async Task ThrowsObservableInvalidOperationExceptionWhenRetrievingSomethingNotATuple()
{
using (var credentialCache = new CredentialCache())
{
await Assert.ThrowsAsync<InvalidOperationException>(
async () => await credentialCache.GetObject<string>("_"));
}
}
开发者ID:kaustubhcs,项目名称:VisualStudio,代码行数:8,代码来源:CredentialCacheTests.cs
示例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)
{
}
开发者ID:ChocolateMonkey,项目名称:onedrive-sdk-csharp,代码行数:12,代码来源:OneDriveClient.cs
示例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;
}
开发者ID:hujirong,项目名称:DevOps,代码行数:9,代码来源:HttpWebRequestBasicAuth.cs
示例7: ThrowsObjectDisposedExceptionWhenDisposed
public async Task ThrowsObjectDisposedExceptionWhenDisposed()
{
using (var credentialCache = new CredentialCache())
{
credentialCache.Dispose();
await Assert.ThrowsAsync<ObjectDisposedException>(
async () => await credentialCache.GetObject<Tuple<string, string>>("_"));
}
}
开发者ID:kaustubhcs,项目名称:VisualStudio,代码行数:9,代码来源:CredentialCacheTests.cs
示例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;
}
开发者ID:noahfalk,项目名称:corefx,代码行数:12,代码来源:CredentialCacheTest.cs
示例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);
}
开发者ID:dotnet,项目名称:corefx,代码行数:12,代码来源:CredentialCacheTest.cs
示例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));
}
开发者ID:alexeysmorkalov,项目名称:GitHubExtension,代码行数:14,代码来源:CredentialCacheTest.cs
示例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);
}
开发者ID:nczsl,项目名称:onedrive-sdk-csharp,代码行数:14,代码来源:OnlineIdServiceInfoProvider.cs
示例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);
}
开发者ID:nczsl,项目名称:onedrive-sdk-csharp,代码行数:16,代码来源:WebAuthenticationBrokerServiceInfoProvider.cs
示例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);
}
开发者ID:dotnet,项目名称:corefx,代码行数:16,代码来源:CredentialCacheTest.cs
示例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;
}
开发者ID:noahfalk,项目名称:corefx,代码行数:16,代码来源:CredentialCacheTest.cs
示例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));
}
开发者ID:nczsl,项目名称:onedrive-sdk-csharp,代码行数:27,代码来源:OneDriveClientExtensions.cs
示例16: RequestWeibo
/// <summary>
/// 发送t_news到微博
/// </summary>
/// <param name="source">app key</param>
/// <param name="username">用户名</param>
/// <param name="password">密码</param>
/// <param name="t_news">需要发送的微博内容</param>
/// <param name="conn">数据库连接</param>
public static void RequestWeibo(string source, string username, string password, string t_news, MySqlConnection conn)
{
string data = "source=" + source + "&status=" + HttpUtility.UrlEncode(t_news);
//准备用户验证数据
string usernamePassword = username + ":" + password;
//准备调用的URL及需要POST的数据
string url = "https://api.weibo.com/2/statuses/update.json";
//准备用于发起请求的HttpWebRequest对象
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);
//准备用于用户验证的凭据
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
httpRequest.Credentials = myCache;
httpRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));
//发起POST请求
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";
Encoding encoding = Encoding.ASCII;
byte[] bytesToPost = encoding.GetBytes(data);
httpRequest.ContentLength = bytesToPost.Length;
Stream requestStream = httpRequest.GetRequestStream();
requestStream.Write(bytesToPost, 0, bytesToPost.Length);
requestStream.Close();
//获取服务端的响应内容
try
{
WebResponse wr = httpRequest.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
receiveStream.Close();
}
catch (Exception e)
{
conn.Open();
MySqlCommand cmd2 = new MySqlCommand("insert into test(msg, date) values ('" + e.ToString() + "','" + DateTime.Now.ToString() + "')", conn);
cmd2.ExecuteNonQuery();
conn.Close();
}
}
开发者ID:RoyalBob,项目名称:Git,代码行数:53,代码来源:PostToWeibo.cs
示例17: CreateCredentialCache
private static CredentialCache CreateCredentialCache(int uriCount, int hostPortCount)
{
var cc = new CredentialCache();
for (int i = 0; i < uriCount; i++)
{
Uri uri = new Uri(UriPrefix + i.ToString());
cc.Add(uri, AuthenticationType, s_credential);
}
for (int i = 0; i < hostPortCount; i++)
{
string host = HostPrefix + i.ToString();
cc.Add(host, Port, AuthenticationType, s_credential);
}
return cc;
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:18,代码来源:CredentialCacheTests.cs
示例18: CreateWebRequest
/// <summary>
/// This method creates secure/non secure web
/// request based on the parameters passed.
/// </summary>
/// <param name="uri"></param>
/// <param name="collHeader">This parameter of type
/// NameValueCollection may contain any extra header
/// elements to be included in this request </param>
/// <param name="RequestMethod">Value can POST OR GET</param>
/// <param name="NwCred">In case of secure request this would be true</param>
/// <returns></returns>
public virtual HttpWebRequest CreateWebRequest(string uri,
NameValueCollection collHeader,
string RequestMethod, bool NwCred)
{
HttpWebRequest webrequest =
(HttpWebRequest)WebRequest.Create(uri);
webrequest.KeepAlive = false;
webrequest.Method = RequestMethod;
int iCount = collHeader.Count;
string key;
string keyvalue;
for (int i = 0; i < iCount; i++)
{
key = collHeader.Keys[i];
keyvalue = collHeader[i];
webrequest.Headers.Add(key, keyvalue);
}
webrequest.ContentType = "text/html";
//"application/x-www-form-urlencoded";
if (ProxyServer.Length > 0)
{
webrequest.Proxy = new
WebProxy(ProxyServer, ProxyPort);
}
webrequest.AllowAutoRedirect = false;
if (NwCred)
{
CredentialCache wrCache =
new CredentialCache();
wrCache.Add(new Uri(uri), "Basic",
new NetworkCredential(UserName, UserPwd));
webrequest.Credentials = wrCache;
}
//Remove collection elements
collHeader.Clear();
return webrequest;
}//End of secure CreateWebRequest
开发者ID:pold500,项目名称:vk_downloader,代码行数:53,代码来源:BaseRequestStream.cs
示例19: DoCredentialTest
public static void DoCredentialTest(string url)
{
var credential = new NetworkCredential();
credential.UserName = "skapila";
credential.Password = "blah" ;
var clientHandler = new HttpClientHandler();
var cc = new CredentialCache();
cc.Add(new Uri("http://httpbin.org"), "Basic", credential);
clientHandler.Credentials = cc;
clientHandler.PreAuthenticate = true;
var httpClient = new HttpClient(clientHandler);
httpClient.MaxResponseContentBufferSize = 256000;
httpClient.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
try{
var responseTask = httpClient.GetAsync(url);
responseTask.Wait();
HttpResponseMessage response = responseTask.Result;
// response.EnsureSuccessStatusCode();
if(response.Content != null) {
var readTask = response.Content.ReadAsStreamAsync();
readTask.Wait();
Console.WriteLine(readTask.Result);
}
else
{
Console.WriteLine(response.StatusCode + " " + response.ReasonPhrase + Environment.NewLine);
}
}
catch(Exception e)
{
Console.WriteLine(e);
return ;
}
return;
}
开发者ID:kapilash,项目名称:dc,代码行数:41,代码来源:HttpWebRequestTest.cs
示例20: ThrowsKeyNotFoundExceptionWhenKeyNotFound
public async Task ThrowsKeyNotFoundExceptionWhenKeyNotFound()
{
using (var credentialCache = new CredentialCache())
{
await Assert.ThrowsAsync<KeyNotFoundException>(
async () => await credentialCache.InvalidateObject<Tuple<string, string>>("git:_"));
await Assert.ThrowsAsync<KeyNotFoundException>(
async () => await credentialCache.InvalidateObject<Tuple<string, string>>("_"));
}
}
开发者ID:kaustubhcs,项目名称:VisualStudio,代码行数:10,代码来源:CredentialCacheTests.cs
注:本文中的CredentialCache类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论