예제 #1
0
        protected override System.Threading.Tasks.Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            var accessToken = request.Headers.GetCookies("token");

            if (accessToken.Count == 0)
            {
                return(base.SendAsync(request, cancellationToken));
            }

            var tokenValue = accessToken[0]["token"].Value;
            var token      = _accessTokenRepository.FindById(tokenValue);

            if (token == null)
            {
                return(base.SendAsync(request, cancellationToken));
            }

            var user = _userRepository.FindById(token.UserId);

            var identity  = new GenericIdentity(user.Username, "Basic");
            var principal = new GenericPrincipal(identity, user.Roles.ToArray());

            Thread.CurrentPrincipal = principal;

            return(base.SendAsync(request, cancellationToken));
        }