public HttpResponseMessage Authenticate(string ClientId, string ClientSecret) { ClientKeys ClientKeys = new ClientKeys() { ClientId = ClientId, ClientSecret = ClientSecret }; if (string.IsNullOrEmpty(ClientKeys.ClientId) && string.IsNullOrEmpty(ClientKeys.ClientSecret)) { HttpResponseMessage response = new HttpResponseMessage(); response = Request.CreateResponse(HttpStatusCode.NotAcceptable, "Not Valid Request"); return(response); } else if (_IAuthenticate.ValidateKeys(ClientKeys)) { var clientkeys = _IAuthenticate.GetClientKeysDetailsbyCLientIDandClientSecret(ClientKeys.ClientId, ClientKeys.ClientSecret); if (clientkeys == null) { HttpResponseMessage response = new HttpResponseMessage(); response = Request.CreateResponse(HttpStatusCode.NotFound, "InValid Keys"); return(response); } else { if (_IAuthenticate.IsTokenAlreadyExists(clientkeys.RegisterAppId.Value)) { _IAuthenticate.DeleteGenerateToken(clientkeys.RegisterAppId.Value); return(GenerateandSaveToken(clientkeys)); } else { return(GenerateandSaveToken(clientkeys)); } } } else { HttpResponseMessage response = new HttpResponseMessage(); response = Request.CreateResponse(HttpStatusCode.NotFound, "InValid Keys"); return(response); } }
public string GetToken(ClientKeys clientKeys, IAuthenticate authenticater, String tokenExpiry, out String sessiontoken) { // sessiontoken = null; // if (string.IsNullOrEmpty(clientKeys.ClientId) && string.IsNullOrEmpty(clientKeys.ClientSecret)) { return("Not Valid Request"); } // string result = string.Empty; if (authenticater.ValidateKeys(clientKeys)) { var clientkeys = authenticater.GetClientKeysDetailsbyCLientIDandClientSecret(clientKeys.ClientId, clientKeys.ClientSecret); if (clientkeys == null) { return("InValid Keys"); } else { if (authenticater.IsTokenAlreadyExists(clientkeys.RegisterAppId.Value)) { authenticater.DeleteGenerateToken(clientkeys.RegisterAppId.Value); var IssuedOn = DateTime.Now; var newToken = authenticater.GenerateToken(clientkeys, IssuedOn); var status = authenticater.InsertToken(clientkeys, tokenExpiry, newToken); if (status == 1) { // Session["_T0k@n_"] = newToken; sessiontoken = newToken; result = "Token generated successfully !!!"; } else { result = "Error in Creating Token"; } } else { var issuedOn = DateTime.Now; var newToken = authenticater.GenerateToken(clientkeys, issuedOn); var status = authenticater.InsertToken(clientkeys, tokenExpiry, newToken); if (status == 1) { // Session["_T0k@n_"] = newToken; sessiontoken = newToken; result = "Token generated successfully !!!"; } else { result = "Error in Creating Token"; } } } } else { result = "Invalid Keys!!!"; } return(result); }