Пример #1
0
        public IHttpActionResult Login(JObject inputData)
        {
            JToken t;
            string username = string.Empty;

            if (inputData.TryGetValue("username", out t))
            {
                username = t.ToString();
            }
            string password = string.Empty;

            if (inputData.TryGetValue("password", out t))
            {
                password = t.ToString();
            }

            MyBasicAuthenticationFilter auth = new MyBasicAuthenticationFilter(true);

            string token = Convert.ToBase64String(Encoding.UTF8.GetBytes(username + ":" + password));

            this.ActionContext.Request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", token);
            auth.OnAuthorization(this.ActionContext);

            if (this.ActionContext.Response.StatusCode == HttpStatusCode.Unauthorized)
            {
                return(new NotFoundWithMessageResult(GetHeaderItem("report")));
            }

            string json = GetHeaderItem("user");

            HttpContext.Current.Response.Headers.Add("loggedUser", json);
            //HttpContext.Current.Response.Headers.Add("token", token);
            return(Ok());
        }
Пример #2
0
        public IHttpActionResult Logout(long id)
        {
            MyBasicAuthenticationFilter auth = new MyBasicAuthenticationFilter();

            auth.Logout(id);
            var requestScope   = this.ActionContext.Request.GetDependencyScope();
            var resolveService = requestScope.GetService(typeof(ITokenService));

            (resolveService as ITokenService).Kill(id);
            return(Ok());
        }