예제 #1
0
 public IHttpActionResult GenerateToken([FromBody] ClientKey clientkeys)
 {
     try
     {
         if (string.IsNullOrEmpty(clientkeys.ClientId) && string.IsNullOrEmpty(clientkeys.ClientSecret))
         {
             return(BadRequest("Not Valid Request"));
         }
         else
         {
             if (_IAuthenticate.ValidateKeys(clientkeys))
             {
                 var keys = _IAuthenticate.GetClientKeysDetailsbyCLientIDandClientSecert(clientkeys.ClientId,
                                                                                         clientkeys.ClientSecret);
                 if (keys == null)
                 {
                     return(NotFound());
                 }
                 else
                 {
                     var result = _IAuthenticate.IsTokenAlreadyExists(clientkeys.DeviceId);
                     if (result)
                     {
                         _IAuthenticate.DeleteGenerateToken(clientkeys.DeviceId);
                         var token = GenerateandSaveToken(clientkeys);
                         return(Ok <TokenManager>(token));
                     }
                     else
                     {
                         var token = GenerateandSaveToken(clientkeys);
                         return(Ok <TokenManager>(token));
                     }
                 }
             }
             else
             {
                 return(NotFound());
             }
         }
     }
     catch (Exception e)
     {
         //Console.WriteLine(e);
         //throw;
         return(BadRequest());
     }
 }
        // POST: api/Authenticate
        public HttpResponseMessage Authenticate([FromBody] ClientKey ClientKeys)
        {
            if (string.IsNullOrEmpty(ClientKeys.ClientID) && string.IsNullOrEmpty(ClientKeys.ClientSecret))
            {
                var message = new HttpResponseMessage(HttpStatusCode.NotAcceptable);
                message.Content = new StringContent("Not Valid Request");
                return(message);
            }
            else
            {
                if (_IAuthenticate.ValidateKeys(ClientKeys))
                {
                    var clientkeys = _IAuthenticate.GetClientKeysDetailsbyCLientIDandClientSecert(ClientKeys.ClientID, ClientKeys.ClientSecret);

                    if (clientkeys == null)
                    {
                        var message = new HttpResponseMessage(HttpStatusCode.NotFound);
                        message.Content = new StringContent("InValid Keys");
                        return(message);
                    }
                    else
                    {
                        if (_IAuthenticate.IsTokenAlreadyExists(clientkeys.CompanyID))
                        {
                            _IAuthenticate.DeleteGenerateToken(clientkeys.CompanyID);

                            return(GenerateandSaveToken(clientkeys));
                        }
                        else
                        {
                            return(GenerateandSaveToken(clientkeys));
                        }
                    }
                }
                else
                {
                    var message = new HttpResponseMessage(HttpStatusCode.NotFound);
                    message.Content = new StringContent("InValid Keys");
                    return(new HttpResponseMessage {
                        StatusCode = HttpStatusCode.NotAcceptable
                    });
                }
            }
        }