当前位置: 首页>>代码示例>>C#>>正文


C# Headers.Token类代码示例

本文整理汇总了C#中System.Net.Http.Headers.Token的典型用法代码示例。如果您正苦于以下问题:C# Token类的具体用法?C# Token怎么用?C# Token使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Token类属于System.Net.Http.Headers命名空间,在下文中一共展示了Token类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OAuthMessageHandler

		public OAuthMessageHandler(HttpMessageHandler innerHandler, IHmacSha1HashProvider hashProvider, string consumerKey, string consumerSecret, Token oAuthToken)
			: base(innerHandler)
		{
            if (hashProvider == null)
                throw new ArgumentNullException("hashProvider");

			if (consumerKey == null)
				throw new ArgumentNullException("consumerKey");

			if (consumerKey.Length == 0)
				throw new ArgumentException("Consumer key cannot be empty.", "consumerKey");

			if (consumerSecret == null)
				throw new ArgumentNullException("consumerSecret");

			if (consumerSecret.Length == 0)
				throw new ArgumentException("Consumer secret cannot be empty.", "consumerSecret");

			if(oAuthToken != null && !oAuthToken.IsValid)
				throw new ArgumentException("OAuth token is not valid.", "oAuthToken");

            if (consumerKey == null)
                throw new ArgumentNullException("consumerKey");

            this.hashProvider = hashProvider;
			this.consumerKey = consumerKey;
			this.consumerSecret = consumerSecret;
			this.oAuthToken = oAuthToken;
		}
开发者ID:jakelauer,项目名称:Vanilla,代码行数:29,代码来源:OAuthMessageHandler.cs

示例2: GetToken

        private static string GetToken(Token token)
        {
            if (token != null && !string.IsNullOrEmpty(token.Key))
            {
                return string.Format("oauth_token=\"{0}\",", token.Key);
            }

            return "";
        }
开发者ID:bartw,项目名称:BeeWee.DiscogsDotNet,代码行数:9,代码来源:OAuthAuthenticator.cs

示例3: GetConsumerKey

        private static string GetConsumerKey(Token consumerToken)
        {
            string consumerKey = null;
            if (consumerToken != null)
            {
                consumerKey = consumerToken.Key;
            }

            return string.Format("oauth_consumer_key=\"{0}\",", consumerToken.Key);
        }
开发者ID:bartw,项目名称:BeeWee.DiscogsDotNet,代码行数:10,代码来源:OAuthAuthenticator.cs

示例4: OAuthAuthenticator

        public OAuthAuthenticator(Token consumerToken, Token oauthToken, string oauthVerifier)
        {
            if (consumerToken == null || string.IsNullOrEmpty(consumerToken.Key) || string.IsNullOrEmpty(consumerToken.Secret))
            {
                throw new ArgumentException("Consumer token or on of its properties can't be null or empty");
            }

            _consumerToken = consumerToken;
            OAuthToken = oauthToken;
            OAuthVerifier = oauthVerifier;
        }
开发者ID:bartw,项目名称:BeeWee.DiscogsDotNet,代码行数:11,代码来源:OAuthAuthenticator.cs

示例5: GeneratePersonalAccessToken

        /// <summary>
        /// Generates a personal access token for use with Visual Studio Online.
        /// </summary>
        /// <param name="targetUri">
        /// The uniform resource indicator of the resource access tokens are being requested for.
        /// </param>
        /// <param name="accessToken"></param>
        /// <param name="tokenScope"></param>
        /// <param name="requireCompactToken"></param>
        /// <returns></returns>
        public async Task<Token> GeneratePersonalAccessToken(TargetUri targetUri, Token accessToken, VstsTokenScope tokenScope, bool requireCompactToken)
        {
            BaseSecureStore.ValidateTargetUri(targetUri);
            BaseSecureStore.ValidateToken(accessToken);
            if (ReferenceEquals(tokenScope, null))
                throw new ArgumentNullException(nameof(tokenScope));

            try
            {
                using (HttpClient httpClient = CreateHttpClient(targetUri, accessToken))
                {
                    if (await PopulateTokenTargetId(targetUri, accessToken))
                    {
                        Uri requestUri = await CreatePersonalAccessTokenRequestUri(httpClient, targetUri, requireCompactToken);

                        using (StringContent content = GetAccessTokenRequestBody(targetUri, accessToken, tokenScope))
                        using (HttpResponseMessage response = await httpClient.PostAsync(requestUri, content))
                        {
                            if (response.IsSuccessStatusCode)
                            {
                                string responseText = await response.Content.ReadAsStringAsync();

                                if (!String.IsNullOrWhiteSpace(responseText))
                                {
                                    // find the 'token : <value>' portion of the result content, if any
                                    Match tokenMatch = null;
                                    if ((tokenMatch = Regex.Match(responseText, @"\s*""token""\s*:\s*""([^\""]+)""\s*", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)).Success)
                                    {
                                        string tokenValue = tokenMatch.Groups[1].Value;
                                        Token token = new Token(tokenValue, TokenType.Personal);

                                        Git.Trace.WriteLine($"personal access token acquisition for '{targetUri}' succeeded.");

                                        return token;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                Git.Trace.WriteLine("! an error occurred.");
            }

            Git.Trace.WriteLine($"personal access token acquisition for '{targetUri}' failed.");

            return null;
        }
开发者ID:Microsoft,项目名称:Git-Credential-Manager-for-Windows,代码行数:60,代码来源:VstsAzureAuthority.cs

示例6: GetSignature

        private static string GetSignature(Token consumerToken, Token token)
        {
            string consumerSecret = null;
            if (consumerToken != null)
            {
                consumerSecret = consumerToken.Secret;
            }

            string tokenSecret = null;
            if (token != null)
            {
                tokenSecret = token.Secret;
            }

            return string.Format("oauth_signature=\"{0}&{1}\",", consumerSecret ?? "", tokenSecret ?? "");
        }
开发者ID:bartw,项目名称:BeeWee.DiscogsDotNet,代码行数:16,代码来源:OAuthAuthenticator.cs

示例7: GetAuthorizationHeader

        private static string GetAuthorizationHeader(Token consumerToken, Token token, string verifier)
        {
            var builder = new StringBuilder();

            builder.Append("OAuth ");
            builder.Append(GetConsumerKey(consumerToken));
            builder.Append(GetNonce());
            builder.Append(GetToken(token));
            builder.Append(GetSignature(consumerToken, token));
            builder.Append("oauth_signature_method=\"PLAINTEXT\",");
            builder.Append(GetTimeStamp());
            builder.Append(GetVerifier(verifier));
            builder.Append("oauth_version=\"1.0\"");

            return builder.ToString();
        }
开发者ID:bartw,项目名称:BeeWee.DiscogsDotNet,代码行数:16,代码来源:OAuthAuthenticator.cs

示例8: TryParseElement

		static bool TryParseElement (Lexer lexer, out TransferCodingWithQualityHeaderValue parsedValue, out Token t)
		{
			parsedValue = null;

			t = lexer.Scan ();
			if (t != Token.Type.Token)
				return false;

			var result = new TransferCodingWithQualityHeaderValue ();
			result.value = lexer.GetStringValue (t);

			t = lexer.Scan ();

			// Parameters parsing
			if (t == Token.Type.SeparatorSemicolon && (!NameValueHeaderValue.TryParseParameters (lexer, out result.parameters, out t) || t != Token.Type.End))
				return false;

			parsedValue = result;
			return true;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:20,代码来源:TransferCodingWithQualityHeaderValue.cs

示例9: GetRefreshTokenAsync

        public async Task<Token> GetRefreshTokenAsync(Token token)
        {

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                var authorizationHeader = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", ClientId, ClientSecret)));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authorizationHeader);

                var form = new Dictionary<string, string>  
                {  
                   {"grant_type", "refresh_token"},
                   {"refresh_token", token.RefreshToken}  
                };

                var tokenResponse = await client.PostAsync(TokenUrl, new FormUrlEncodedContent(form));

                return await tokenResponse.Content.ReadAsAsync<Token>(new[] { new JsonMediaTypeFormatter() });
            }

        }
开发者ID:jango2015,项目名称:WebApiBearerToken,代码行数:21,代码来源:ServiceRest.cs

示例10: TryParseElement

		static bool TryParseElement (Lexer lexer, out MediaTypeWithQualityHeaderValue parsedValue, out Token t)
		{
			parsedValue = null;

			string media;
			List<NameValueHeaderValue> parameters = null;
			var token = TryParseMediaType (lexer, out media);
			if (token == null) {
				t = Token.Empty;
				return false;
			}

			t = token.Value;
			if (t == Token.Type.SeparatorSemicolon && (!NameValueHeaderValue.TryParseParameters (lexer, out parameters, out t) || t != Token.Type.End))
				return false;

			parsedValue = new MediaTypeWithQualityHeaderValue ();
			parsedValue.media_type = media;
			parsedValue.parameters = parameters;
			return true;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:21,代码来源:MediaTypeWithQualityHeaderValue.cs

示例11: GetQuotedStringValue

		public string GetQuotedStringValue (Token start)
		{
			return s.Substring (start.StartPosition + 1, start.EndPosition - start.StartPosition - 2);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:4,代码来源:Lexer.cs

示例12: GetStringValue

		public string GetStringValue (Token start, Token end)
		{
			return s.Substring (start.StartPosition, end.EndPosition - start.StartPosition);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:4,代码来源:Lexer.cs

示例13: GetNextToken

 protected void GetNextToken()
 {
     NextToken = ReadToken();
 }
开发者ID:rollingthunder,项目名称:Link,代码行数:4,代码来源:LinkHeaderParser.cs

示例14: ValidateToken

        /// <summary>
        /// <para>Validates that <see cref="Token"/> are valid to grant access to the Visual Studio
        /// Online service represented by the <paramref name="targetUri"/> parameter.</para>
        /// </summary>
        /// <param name="targetUri">Uniform resource identifier for a VSTS service.</param>
        /// <param name="token">
        /// <see cref="Token"/> expected to grant access to the VSTS service.
        /// </param>
        /// <returns>True if successful; otherwise false.</returns>
        public async Task<bool> ValidateToken(TargetUri targetUri, Token token)
        {
            BaseSecureStore.ValidateTargetUri(targetUri);
            BaseSecureStore.ValidateToken(token);

            // personal access tokens are effectively credentials, treat them as such
            if (token.Type == TokenType.Personal)
                return await this.ValidateCredentials(targetUri, (Credential)token);

            try
            {
                // create an request to the VSTS deployment data end-point
                HttpWebRequest request = GetConnectionDataRequest(targetUri, token);

                Git.Trace.WriteLine($"validating token against '{request.Host}'.");

                // send the request and wait for the response
                using (HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse)
                {
                    // we're looking for 'OK 200' here, anything else is failure
                    Git.Trace.WriteLine($"server returned: '{response.StatusCode}'.");
                    return response.StatusCode == HttpStatusCode.OK;
                }
            }
            catch (WebException webException)
            {
                Git.Trace.WriteLine($"! server returned: '{webException.Message}'.");
            }
            catch
            {
                Git.Trace.WriteLine("! unexpected error");
            }

            Git.Trace.WriteLine($"token validation for '{targetUri}' failed.");
            return false;
        }
开发者ID:Microsoft,项目名称:Git-Credential-Manager-for-Windows,代码行数:45,代码来源:VstsAzureAuthority.cs

示例15: TryParseElement

		static bool TryParseElement (Lexer lexer, out ProductHeaderValue parsedValue, out Token t)
		{
			parsedValue = null;

			t = lexer.Scan ();
			if (t != Token.Type.Token)
				return false;

			parsedValue = new ProductHeaderValue ();
			parsedValue.Name = lexer.GetStringValue (t);

			t = lexer.Scan ();
			if (t == Token.Type.SeparatorSlash) {
				t = lexer.Scan ();
				if (t != Token.Type.Token)
					return false;

				parsedValue.Version = lexer.GetStringValue (t);
				t = lexer.Scan ();
			}

			return true;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:23,代码来源:ProductHeaderValue.cs


注:本文中的System.Net.Http.Headers.Token类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。