本文整理汇总了C#中Credentials.GetToken方法的典型用法代码示例。如果您正苦于以下问题:C# Credentials.GetToken方法的具体用法?C# Credentials.GetToken怎么用?C# Credentials.GetToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Credentials
的用法示例。
在下文中一共展示了Credentials.GetToken方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Authenticate
///<summary>
///Authenticate a request using the OAuth2 Token (sent in a header) authentication scheme
///</summary>
///<param name="request">The request to authenticate</param>
///<param name="credentials">The credentials to attach to the request</param>
///<remarks>
///See the <a href="http://developer.github.com/v3/#oauth2-token-sent-in-a-header">OAuth2 Token (sent in a header) documentation</a> for more information.
///</remarks>
public void Authenticate(IRequest request, Credentials credentials)
{
Ensure.ArgumentNotNull(request, "request");
Ensure.ArgumentNotNull(credentials, "credentials");
Ensure.ArgumentNotNull(credentials.Password, "credentials.Password");
var token = credentials.GetToken();
if (credentials.Login != null)
{
throw new InvalidOperationException("The Login is not null for a token authentication request. You " +
"probably did something wrong.");
}
if (token != null)
{
request.Headers["Authorization"] = string.Format(CultureInfo.InvariantCulture, "Token {0}", token);
}
}