using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin;

namespace OwinSample
{
    public class SecurePassiveController: ApiController
    {

        public async Task<string> GetUserName()
        {
            var authenticationManager = Request.GetOwinContext().Authentication;
            var authResult = await authenticationManager.AuthenticateAsync("Basic");

            if (authResult == null || authResult.Identity == null) throw new HttpResponseException(HttpStatusCode.Unauthorized);

            return authResult.Identity.Name;
        }
    }
}
