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


C# IHttpRequest.GetBasicAuthUserAndPassword方法代码示例

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


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

示例1: AuthenticateBasicAuth

        //Also shared by RequiredRoleAttribute and RequiredPermissionAttribute
        public static User AuthenticateBasicAuth(IHttpRequest req, IHttpResponse res)
        {
            var userCredentialsPair = req.GetBasicAuthUserAndPassword();
            var email = userCredentialsPair.HasValue ? userCredentialsPair.Value.Key : String.Empty;
            var password = userCredentialsPair.HasValue ? userCredentialsPair.Value.Value : String.Empty;

            User user = null;
            bool isValid = false;

            using (var session = NHibernateHelper.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var userQuery = session.QueryOver<User>()
                        .Where(table => table.Email == email)
                        .And(table => table.Password == password);

                    user = userQuery.SingleOrDefault();

                    transaction.Commit();

                    isValid = (user != null);
                }
            }

            if (!isValid)
            {
                res.StatusCode = (int)HttpStatusCode.Unauthorized;
                res.EndServiceStackRequest();
            }

            return user;
        }
开发者ID:jasonpang,项目名称:Meetup,代码行数:34,代码来源:RequiresAuthenticationAttribute.cs

示例2: Authorize

 public void Authorize(IHttpRequest httpRequest, IHttpResponse httpResponse, object arg3)
 {
     var apikey = httpRequest.GetBasicAuthUserAndPassword();
     bool authorized = IsAuthorized(apikey);
     if (!authorized)
     {
         httpResponse.ReturnAuthRequired();
         return;
     }
     // Don't need to do anything if a valid API key
 }
开发者ID:alexcpendleton,项目名称:Sandbox,代码行数:11,代码来源:Auth.cs

示例3: AuthenticateIfBasicAuth

 public static void AuthenticateIfBasicAuth(IHttpRequest req, IHttpResponse res)
 {
     var userPass = req.GetBasicAuthUserAndPassword();
     if (userPass != null)
     {
         var authService = req.TryResolve<AuthService>();
         authService.RequestContext = new HttpRequestContext(req, res, null);
         var response = authService.Post(new Auth.Auth {
             provider = BasicAuthProvider.Name,
             UserName = userPass.Value.Key,
             Password = userPass.Value.Value
         });
     }
 }
开发者ID:niemyjski,项目名称:ServiceStack,代码行数:14,代码来源:AuthenticateAttribute.cs

示例4: AuthenticateIfBasicAuth

        //Also shared by RequiredRoleAttribute and RequiredPermissionAttribute
        public static void AuthenticateIfBasicAuth(IHttpRequest req, IHttpResponse res)
        {
            //Need to run SessionFeature filter since its not executed before this attribute (Priority -100)
            SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId()

            var userPass = req.GetBasicAuthUserAndPassword();
            if (userPass != null)
            {
                var authService = req.TryResolve<AuthService>();
                authService.RequestContext = new HttpRequestContext(req, res, null);
                var response = authService.Post(new Auth.Auth {
                    provider = BasicAuthProvider.Name,
                    UserName = userPass.Value.Key,
                    Password = userPass.Value.Value
                });
            }
        }
开发者ID:half-evil,项目名称:ServiceStack,代码行数:18,代码来源:AuthenticateAttribute.cs

示例5: Execute

        public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
        {
            if (AuthService.AuthConfigs == null) throw new InvalidOperationException("The AuthService must be initialized by calling "
                 + "AuthService.Init to use an authenticate attribute");

            var matchingOAuthConfigs = AuthService.AuthConfigs.Where(x =>
                            this.Provider.IsNullOrEmpty()
                            || x.Provider == this.Provider).ToList();

            if (matchingOAuthConfigs.Count == 0)
            {
                res.WriteError(req, requestDto, "No OAuth Configs found matching {0} provider"
                    .Fmt(this.Provider ?? "any"));
                res.Close();
                return;
            }

            var userPass = req.GetBasicAuthUserAndPassword();
            if (userPass != null)
            {
                var authService = req.TryResolve<AuthService>();
                authService.RequestContext = new HttpRequestContext(req, res, requestDto);
                var response = authService.Post(new Auth.Auth {
                    provider = BasicAuthConfig.Name,
                    UserName = userPass.Value.Key,
                    Password = userPass.Value.Value
                });
            }

            using (var cache = req.GetCacheClient())
            {
                var sessionId = req.GetPermanentSessionId();
                var session = sessionId != null ? cache.GetSession(sessionId) : null;

                if (session == null || !matchingOAuthConfigs.Any(x => session.IsAuthorized(x.Provider)))
                {
                    res.StatusCode = (int)HttpStatusCode.Unauthorized;
                    res.AddHeader(HttpHeaders.WwwAuthenticate, "{0} realm=\"{1}\""
                        .Fmt(matchingOAuthConfigs[0].Provider, matchingOAuthConfigs[0].AuthRealm));

                    res.Close();
                }
            }
        }
开发者ID:austinvernsonger,项目名称:ServiceStack,代码行数:44,代码来源:AuthenticateAttribute.cs

示例6: getUser

 public static ApiUser getUser(IHttpRequest request)
 {
     var basicAuth = request.GetBasicAuthUserAndPassword();
     string key = basicAuth.Value.Key;
     string api_token = basicAuth.Value.Value;
     if (key.Length != 13 || !key[6].Equals('-'))
         throw new HttpError(HttpStatusCode.Forbidden, "Org/Instance is not correct.");
     string[] split = key.Split('-');
     string org_key = split[0];
     string instance_key = split[1];
     if (api_token.Length != 32)
         throw new HttpError(HttpStatusCode.Forbidden, "Token is not correct.");
     ApiUser apiUser = new ApiUser(api_token);
     if (!apiUser.ValidateAccess(org_key, instance_key))
         throw new HttpError(HttpStatusCode.Forbidden, "User is Inactive or does not have access to this Organization/Instance");
     return apiUser;
 }
开发者ID:evgeniynet,项目名称:APIBeta,代码行数:17,代码来源:ApiUser.cs

示例7: Execute

        public override void Execute(IHttpRequest httpReq, IHttpResponse httpResp, object request)
        {
            var basicAuth = httpReq.GetBasicAuthUserAndPassword();
            ApiRequest apiRequest = request as ApiRequest;
            if (apiRequest == null)
            {
                //Custom Auth needed
                return;
            }

            string api_token = "";

            if (basicAuth == null)
            {
                api_token = httpReq.QueryString["api_token"];

                if (string.IsNullOrEmpty(api_token))
                {
                    httpResp.AddHeader(HttpHeaders.WwwAuthenticate, "Basic realm=\"/login\"");
                    throw new HttpError(HttpStatusCode.Unauthorized, "Invalid BasicAuth credentials");
                }
                else if (api_token.Length != 32)
                    throw new HttpError(HttpStatusCode.Forbidden, "Token is not correct.");
            }
            else
            {
                string key = basicAuth.Value.Key;
                string password = basicAuth.Value.Value;
                if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(password))
                    throw new HttpError(HttpStatusCode.Forbidden, "Token is not correct.");
                if (key == "x")
                {
                    if (password.Length != 32)
                        throw new HttpError(HttpStatusCode.Forbidden, "Token is not correct.");
                    apiRequest.api_token = password;
                }
                else
                {
                    apiRequest.ApiUser = ApiUser.getUser(httpReq);
                }
            }
        }
开发者ID:evgeniynet,项目名称:APIBeta,代码行数:42,代码来源:ApiRequest.cs


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