public override Task OnAuthorizationAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
        {
            var header = actionContext.Request.Headers.Authorization;

            if (header == null || header.Scheme != SampleIdentity.AuthenticationTypeScheme)
            {
                return(base.OnAuthorizationAsync(actionContext, cancellationToken));
            }
            var authParameter = header.Parameter;

            if (string.IsNullOrWhiteSpace(authParameter))
            {
                return(null);
            }
            authParameter = Encoding.Default.GetString(Convert.FromBase64String(authParameter));
            var authToken = authParameter.Split(':');

            if (authToken.Length < 2)
            {
                return(null);
            }
            if (!_userServiceImp.ValidateUser(authToken[0], authToken[1]))
            {
                return(ChallengeAsync(actionContext, cancellationToken));
            }

            var userIdentity = new SampleIdentity(authToken[0], authToken[1]);
            var principal    = new GenericPrincipal(userIdentity, null);

            Thread.CurrentPrincipal = principal;

            return(base.OnAuthorizationAsync(actionContext, cancellationToken));
        }
        public override Task OnAuthorizationAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
        {
            var header = actionContext.Request.Headers.Authorization;
            if (header == null || header.Scheme != SampleIdentity.AuthenticationTypeScheme)
                return base.OnAuthorizationAsync(actionContext, cancellationToken);
            var authParameter = header.Parameter;
            if(string.IsNullOrWhiteSpace(authParameter))
                return null;
            authParameter = Encoding.Default.GetString(Convert.FromBase64String(authParameter));
            var authToken = authParameter.Split(':');
            if (authToken.Length < 2)
                return null;
            if (!_userServiceImp.ValidateUser(authToken[0], authToken[1]))
            {
                return ChallengeAsync(actionContext, cancellationToken);
            }

            var userIdentity =new SampleIdentity(authToken[0], authToken[1]);
            var principal = new GenericPrincipal(userIdentity, null);

            Thread.CurrentPrincipal = principal;

            return base.OnAuthorizationAsync(actionContext, cancellationToken);
        }