Ejemplo n.º 1
0
        public static void AuthenticateIfBasicAuth(IRequest req, IResponse 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 = ((IResolver)req).TryResolve <AuthenticateService>();
                authService.Request = req;
                var response = authService.Post(new Authenticate
                {
                    provider = BasicAuthProvider.Name,
                    UserName = userPass.Value.Key,
                    Password = userPass.Value.Value
                });
            }
        }
Ejemplo n.º 2
0
        public static void AuthenticateIfDigestAuth(IRequest req, IResponse 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 digestAuth = req.GetDigestAuth();

            if (digestAuth != null)
            {
                var authService = ((IResolver)req).TryResolve <AuthenticateService>();
                authService.Request = req;
                var response = authService.Post(new Authenticate
                {
                    provider = DigestAuthProvider.Name,
                    nonce    = digestAuth["nonce"],
                    uri      = digestAuth["uri"],
                    response = digestAuth["response"],
                    qop      = digestAuth["qop"],
                    nc       = digestAuth["nc"],
                    cnonce   = digestAuth["cnonce"],
                    UserName = digestAuth["username"]
                });
            }
        }