コード例 #1
0
ファイル: Authentication.cs プロジェクト: mkeeton/BasicMVC
        public static AuthenticationResponse GetAuthenticationResponse()
        {
            AuthenticationResponse _Response;
              try
              {
              using (var client = new HttpClient())
              {
            client.BaseAddress = new Uri(System.Web.Configuration.WebConfigurationManager.AppSettings["SSOURL"]);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            // New code:
            HttpResponseMessage response = client.GetAsync("API/Authentication/" + Repositories.CookieRepository.GetCookieValue("SessionID", Guid.NewGuid().ToString())).Result;
            if (response.IsSuccessStatusCode)
            {
              _Response  = response.Content.ReadAsAsync<AuthenticationResponse>().Result;
            }
            else
            {
              _Response = new AuthenticationResponse();
              _Response.ResponseCode = AuthenticationResponse.AuthenticationResponseCode.Error;
            }
              }
              }
              catch(Exception)
              {
            _Response = new AuthenticationResponse();
            _Response.ResponseCode = AuthenticationResponse.AuthenticationResponseCode.Error;
              }
              return _Response;
        }
コード例 #2
0
 // GET api/<controller>/5
 public async Task<AuthenticationResponse> Get(Guid id)
 {
   AuthenticationResponse objReturn = new AuthenticationResponse();
   objReturn.Id = Guid.NewGuid();
   try
   { 
     string strSource = Request.RequestUri.PathAndQuery; 
     objReturn.ResponseCode = AuthenticationResponse.AuthenticationResponseCode.Unknown;
     objReturn.RedirectURL = Request.RequestUri.Scheme + "://" + Request.RequestUri.Authority + "/Account/ConfirmLogin/";
     ClientSession _clientSession = await WorkManager.SessionManager.FindByClientAsync(id);
     if(_clientSession==null)
     {
       Login _Login = await WorkManager.LoginManager.FindOpenByClientIdAsync(id);
       if(_Login!=null)
       {
         objReturn.UserId = _Login.UserId;
         objReturn.ResponseCode = AuthenticationResponse.AuthenticationResponseCode.LoggedIn;
         objReturn.RedirectURL = "";
       }
     }
     else
     { 
       objReturn.ResponseCode = AuthenticationResponse.AuthenticationResponseCode.NotLoggedIn;
       objReturn.RedirectURL = Request.RequestUri.Scheme + "://" + Request.RequestUri.Authority + "/Account/Login/";
     }
   }
   catch(Exception ex)
   {
     objReturn.ResponseCode = AuthenticationResponse.AuthenticationResponseCode.Error;
     objReturn.RedirectURL = "";
   }        
   return objReturn;
 }