public RequireBasicAuthenticationAttribute(string basicRealm, string requiredUserName, string requiredPassword, IBasicAuthenticationProvider authenticator)
 {
     _basicRealm = basicRealm;
     if (requiredUserName != null || requiredPassword != null)
         _requiredCredentials = new BasicAuthenticationCredentials(requiredUserName, requiredPassword);
     _authenticator = authenticator;
 }
Exemplo n.º 2
0
        public bool IsAuthenticatedWithCredentials(BasicAuthenticationCredentials requiredCredentials)
        {
            if (!IsAuthenticated())
                return false;

            var credentials = GetCurrentUserCredentials();
            var userNameMatch = credentials.UserName == requiredCredentials.UserName;
            var passwordMatch = credentials.Password == requiredCredentials.Password;

            return userNameMatch && passwordMatch;
        }
Exemplo n.º 3
0
        public BasicAuthenticationCredentials GetCurrentUserCredentials()
        {
            var request = HttpContext.Current.Request;
            var header = request.Headers["Authorization"];
            if (string.IsNullOrWhiteSpace(header))
                return null;

            var authString = Convert.FromBase64String(header.Substring(6));
            var rawCredentials = System.Text.Encoding.ASCII.GetString(authString).Split(':');
            var credentials = new BasicAuthenticationCredentials(rawCredentials[0], rawCredentials[1]);

            return credentials;
        }
Exemplo n.º 4
0
        public bool IsAuthenticatedWithCredentials(BasicAuthenticationCredentials requiredCredentials)
        {
            if (!IsAuthenticated())
            {
                return(false);
            }

            var credentials   = GetCurrentUserCredentials();
            var userNameMatch = credentials.UserName == requiredCredentials.UserName;
            var passwordMatch = credentials.Password == requiredCredentials.Password;

            return(userNameMatch && passwordMatch);
        }
Exemplo n.º 5
0
        public BasicAuthenticationCredentials GetCurrentUserCredentials()
        {
            var request = HttpContext.Current.Request;
            var header  = request.Headers["Authorization"];

            if (string.IsNullOrWhiteSpace(header))
            {
                return(null);
            }

            var authString     = Convert.FromBase64String(header.Substring(6));
            var rawCredentials = System.Text.Encoding.ASCII.GetString(authString).Split(':');
            var credentials    = new BasicAuthenticationCredentials(rawCredentials[0], rawCredentials[1]);

            return(credentials);
        }