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


C# AuthenticationHeaderValue.ToString方法代码示例

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


在下文中一共展示了AuthenticationHeaderValue.ToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToString_UseBothNoParameterAndSetParameter_AllSerializedCorrectly

        public void ToString_UseBothNoParameterAndSetParameter_AllSerializedCorrectly()
        {
            using (HttpResponseMessage response = new HttpResponseMessage())
            {
                string input = string.Empty;

                AuthenticationHeaderValue auth = new AuthenticationHeaderValue("Digest",
                    "qop=\"auth\",algorithm=MD5-sess,nonce=\"+Upgraded+v109e309640b\",charset=utf-8,realm=\"Digest\"");

                Assert.Equal(
                    "Digest qop=\"auth\",algorithm=MD5-sess,nonce=\"+Upgraded+v109e309640b\",charset=utf-8,realm=\"Digest\"",
                    auth.ToString());
                response.Headers.ProxyAuthenticate.Add(auth);
                input += auth.ToString();

                auth = new AuthenticationHeaderValue("Negotiate");
                Assert.Equal("Negotiate", auth.ToString());
                response.Headers.ProxyAuthenticate.Add(auth);
                input += ", " + auth.ToString();

                auth = new AuthenticationHeaderValue("Custom", ""); // empty string should be treated like 'null'.
                Assert.Equal("Custom", auth.ToString());
                response.Headers.ProxyAuthenticate.Add(auth);
                input += ", " + auth.ToString();

                string result = response.Headers.ProxyAuthenticate.ToString();
                Assert.Equal(input, result);
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:29,代码来源:AuthenticationHeaderValueTest.cs

示例2: TrottlingAuthenticate

        public void TrottlingAuthenticate()
        {
            Database.SetInitializer(new ManahostManagerInitializer());
            using (ManahostManagerDAL prectx = new ManahostManagerDAL())
            {
                prectx.Database.Delete();
            }
            using (var server = TestServer.Create<WebApiApplicationThrottle>())
            {
                HttpResponseMessage response = null;
                response = server.CreateRequest("/token").And((x) => x.Content = new StringContent(string.Format("grant_type=password&username={0}&password={1}&client_id=UNITTEST&client_secret=BLAHBLAHCAR", ControllerUtils.username, ControllerUtils.password), Encoding.UTF8, "application/x-www-form-urlencoded")).PostAsync().Result;
                Assert.AreEqual(response.StatusCode, HttpStatusCode.OK, "STATUS AUTHENTIFICATIOn");

                TokenAuth token = response.Content.ReadAsAsync<TokenAuth>().Result;
                AuthenticationHeaderValue headerValueAuthentication = new AuthenticationHeaderValue("Bearer", token.access_token);

                for (int i = 0; i < 4000; i++)
                {
                    response = server.CreateRequest("/api/Account").AddHeader("Authorization", headerValueAuthentication.ToString()).GetAsync().Result;
                    Assert.AreEqual(response.StatusCode, HttpStatusCode.OK, string.Format("STATUS Account GET I : {0}", i));
                }
                response = server.CreateRequest("/api/Account").AddHeader("Authorization", headerValueAuthentication.ToString()).GetAsync().Result;
                Assert.AreEqual((int)response.StatusCode, 429, "STATUS 429");
            }
        }
开发者ID:charla-n,项目名称:ManahostManager,代码行数:25,代码来源:ThrottlingTest.cs

示例3: ParseAuthHeader

        public static IDictionary<string, string> ParseAuthHeader(AuthenticationHeaderValue header)
        {
            if(header == null) {
                return null;
            }

            var retVal = new Dictionary<string, string>();
            var raw = header.Parameter;
            var regex = new Regex("(\\w+)=((\\w+)|\"([^\"]+))");
            var matches = regex.Matches(raw);
            if(matches.Count > 0) { 
                var groups = matches[0].Groups;
                var key = groups[1].Value;
                var k = groups[3];
                if(!k.Success) {
                    k = groups[4];
                }

                retVal[key] = k.Value;
                retVal["Scheme"] = header.Scheme;
            }

            retVal["WWW-Authenticate"] = header.ToString();
            return retVal;
        }
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:25,代码来源:AuthUtils.cs

示例4: ParseCredentials

        private static BasicCredentials ParseCredentials(AuthenticationHeaderValue authHeader)
        {
            try
            {
                var credentials = Encoding.ASCII.GetString(Convert.FromBase64String(authHeader.ToString().Substring(6))).Split(':');

                return new BasicCredentials
                {
                    Username = credentials[0],
                    Password = credentials[1]
                };
            }
            catch { }

            return new BasicCredentials();
        }
开发者ID:AravindRK,项目名称:TestNuGet,代码行数:16,代码来源:BasicAuthenticationHandler.cs

示例5: ParseCredentials

        private static BasicCredentials ParseCredentials(AuthenticationHeaderValue authHeader)
        {
            try
            {
                var credentials = Encoding.ASCII.GetString(Convert.FromBase64String(authHeader.ToString().Substring(6)));
                int splitOn = credentials.IndexOf(':');

                return new BasicCredentials
                {
                    Username = credentials.Substring(0, splitOn),
                    Password = credentials.Substring(splitOn + 1)
                };
            }
            catch { }

            return new BasicCredentials();
        }
开发者ID:aehyok,项目名称:WebAPIContrib,代码行数:17,代码来源:BasicAuthenticationHandler.cs

示例6: OnAuthentication

        public void OnAuthentication(AuthenticationContext filterContext)
        {
            IPrincipal user;

            string sessionid = filterContext.HttpContext.Session.SessionID;

            if (CheckIsAuthented(filterContext, out user))
            {
                filterContext.Principal = user;
            }
            else
            {
                string parameter = string.Format("realm=\"{0}\"", filterContext.RequestContext.HttpContext.Request.Url.DnsSafeHost);
                AuthenticationHeaderValue challenge = new AuthenticationHeaderValue(BasicAuthenticationScheme, parameter);
                filterContext.HttpContext.Response.Headers[WwwAuthenticationHeaderName] = challenge.ToString();
                filterContext.Result = new HttpUnauthorizedResult();
            }
        }
开发者ID:Skynetfy,项目名称:MyTestProgram,代码行数:18,代码来源:BasicAuthenticateAttribute.cs

示例7: ProcessUnauthenticatedRequest

 protected virtual void ProcessUnauthenticatedRequest(AuthenticationContext filterContext)
 {
     string parameter = string.Format("realm=\"{0}\"", filterContext.RequestContext.HttpContext.Request.Url.DnsSafeHost);
     AuthenticationHeaderValue challenge = new AuthenticationHeaderValue(BasicAuthenticationScheme, parameter);
     filterContext.HttpContext.Response.Headers[WwwAuthenticationHeaderName] = challenge.ToString();
     filterContext.Result = new HttpUnauthorizedResult();
 }
开发者ID:Skynetfy,项目名称:MyTestProgram,代码行数:7,代码来源:AuthenticateAttribute.cs

示例8: ValidateAuthorisationHeader

        /// <summary>
        /// Validates whether the authentication key exists in a correct format or not.
        /// </summary>
        /// <param name="header">Authentication header value.</param>
        /// <returns>Returns <c>True</c>, if the authentication key exists in a correct format; otherwise returns <c>False</c>.</returns>
        public bool ValidateAuthorisationHeader(AuthenticationHeaderValue header)
        {
            if (header == null)
            {
                return false;
            }

            var token = header.ToString();
            if (String.IsNullOrWhiteSpace(token))
            {
                return false;
            }

            if (!token.StartsWith("token "))
            {
                return false;
            }

            return true;
        }
开发者ID:esironal,项目名称:GitHub-API-Cache,代码行数:25,代码来源:WebClientService.cs


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