public ActionResult Generate() { try { ClientKey cKey = new ClientKey(); var keyExists = _clientKeysRepo.IsUniqueKeyAlreadyGenerate(Convert.ToInt32(Session["UserId"])); if (keyExists) { cKey = _clientKeysRepo.GetGenerateUniqueKeyByUserID(Convert.ToInt32(Session["UserId"])); } else { string clientId = string.Empty; string clientSecret = String.Empty; int deviceId = 0; _clientKeysRepo.GenerateUniqueKey(out clientId, out clientSecret); cKey.ClientKeyId = 0; cKey.Createdon = DateTime.Now; cKey.ClientId = "100"; cKey.ClientSecret = clientSecret; cKey.DeviceId = "0"; cKey.UserId = Convert.ToInt32(Session["UserId"]); _clientKeysRepo.SaveClientIDandClientSecert(cKey); } return(View(cKey)); } catch (Exception e) { //Console.WriteLine(e); //throw; return(View()); } }
public override void Process() { UserProxy user = (UserProxy)Session; user.InitS2C(ClientKey.RawData()); base.Process(); }
public ActionResult GenerateKeys(ClientKey clientkeys) { try { string clientID = string.Empty; string clientSecert = string.Empty; //Generate Keys _IClientKeys.GenerateUniqueKey(out clientID, out clientSecert); //Updating ClientID and ClientSecert //var company = _IRegisterCompany.FindCompanyByUserId(Convert.ToInt32(Session["UserID"])); //clientkeys.CompanyID = company.CompanyID; clientkeys.CompanyID = 0; clientkeys.CreateOn = DateTime.Now; clientkeys.ClientID = clientID; clientkeys.ClientSecret = clientSecert; clientkeys.UserID = Convert.ToInt32(Session["UserID"]); _IClientKeys.UpdateClientIDandClientSecert(clientkeys); return(RedirectToAction("GenerateKeys")); } catch (Exception ex) { return(View()); } }
private TokenManager GenerateandSaveToken(ClientKey clientkeys) { var IssuedOn = DateTime.Now; var newToken = _IAuthenticate.GenerateToken(clientkeys, IssuedOn); TokenManager token = new TokenManager(); token.TokenId = 0; token.TokenKey = newToken; token.DeviceId = clientkeys.DeviceId; token.IssueOn = IssuedOn; token.ExpiersOn = DateTime.Now.AddMinutes(Convert.ToInt32(ConfigurationManager.AppSettings["TokenExpiry"])); token.CreatedOn = DateTime.Now; var result = _IAuthenticate.InsertToken(token); return(token); //if (result == 1) //{ // HttpResponseMessage response = new HttpResponseMessage(); // response = Request.CreateResponse(HttpStatusCode.OK, "Authorized"); // response.Headers.Add("Token", newToken); // response.Headers.Add("TokenExpiry", ConfigurationManager.AppSettings["TokenExpiry"]); // response.Headers.Add("Access-Control-Expose-Headers", "Token,TokenExpiry"); // return response; //} //else //{ // var message = new HttpResponseMessage(HttpStatusCode.NotAcceptable); // message.Content = new StringContent("Error in Creating Token"); // return message; //} }
public void StorePair(ClientKey ck, string value) { if (m_pairs.ContainsKey(ck)) throw new FaultException("Duplicated Key: " + ck.Key +" of the client: " + ck.ClientName); m_pairs.TryAdd(ck, value); }
public AcquireDeviceCodeHandler(Authenticator authenticator, string resource, string clientId, string extraQueryParameters) { this.authenticator = authenticator; this.callState = AcquireTokenHandlerBase.CreateCallState(this.authenticator.CorrelationId); this.clientKey = new ClientKey(clientId); this.resource = resource; this.extraQueryParameters = extraQueryParameters; }
public DictionaryRequestParameters(string resource, ClientKey clientKey) { if (!string.IsNullOrWhiteSpace(resource)) { this[OAuthParameter.Resource] = resource; } clientKey.AddToParameters(this); }
public String ReadValue(ClientKey ck) { if (!m_pairs.ContainsKey(ck)) throw new FaultException("Key " + ck.Key + " doesn't exists of the client: " + ck.ClientName); String res; m_pairs.TryGetValue(ck, out res); return res; }
public virtual int _GetUniqueIdentifier() { var hashCode = 399326290; hashCode = hashCode * -1521134295 + (Id?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (ClientKey?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (IPAddress?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (SessionId?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (ConnectedOn?.GetHashCode() ?? 0); return(hashCode); }
public static Either <Error, List <ClientKey> > listClientKeys( string baseUrl, ProjectData projectData, ApiKey key ) { return(request( $"{baseUrl}/api/0/projects/{projectData.organizationSlug}/{projectData.projectSlug}/keys/", Request.get, key, new Dictionary <string, string>() ).mapRight(www => ((List <object>)Json.Deserialize(www.text)). Select(item => ClientKey.readFromJson((Dictionary <string, object>)item)). ToList() )); }
public static Either <Error, ClientKey> createClientKey( string baseUrl, ProjectData projectData, ApiKey key, string name ) { var json = Json.Serialize(F.dict(F.t("name", name))); return(request( $"{baseUrl}/api/0/projects/{projectData.organizationSlug}/{projectData.projectSlug}/keys/", Request.post(Encoding.UTF8.GetBytes(json)), key, new Dictionary <string, string>() ).mapRight(www => ClientKey.readFromJson( (Dictionary <string, object>)Json.Deserialize(www.text) ))); }
public ClientKeyVm(ClientKey view = null) { if (view == null) { return; } _id = view.Id; _clientId = view.ClientId; _apiKey = view.APIKey; _apiSecret = view.APISecret; _createDate = view.CreateDate; _updateDate = view.UpdateDate; Status = view.Status; }
/// <summary> /// Use to update the database record. /// </summary> /// <param name="view">ClientKey</param> /// <returns>ClientKey</returns> internal virtual ClientKey ToEntity(ClientKey view = null) { if (view == null) { view = new ClientKey(); } view.Status = Status; if (_createDate == new DateTime()) { view.UpdateDate = DateTime.UtcNow; } return(view); }
public bool ValidateKeys(ClientKey ClientKeys) { try { var result = (from keys in _context.Key where keys.ClientId == ClientKeys.ClientId && keys.ClientSecret == ClientKeys.ClientSecret select keys).Count(); return(result > 0); } catch (Exception e) { //Console.WriteLine(e); throw; } }
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()); } }
public int UpdateClientIDandClientSecert(ClientKey ClientKeys) { try { var userId = ClientKeys.UserId; var dpt = GetGenerateUniqueKeyByUserID(userId); _context.Entry(dpt).CurrentValues.SetValues(ClientKeys); return(_context.SaveChanges()); } catch (Exception e) { //Console.WriteLine(e); throw; } //_context.Entry(ClientKeys).State=EntityState.Modified; //return _context.SaveChangesAsync().Result; }
public ActionResult GenerateKeys() { try { ClientKey clientkeys = new ClientKey(); // Validating ClientID and ClientSecert already Exists var keyExists = _IClientKeys.IsUniqueKeyAlreadyGenerate(Convert.ToInt32(Session["UserID"])); if (keyExists) { // Getting Generate ClientID and ClientSecert Key By UserID clientkeys = _IClientKeys.GetGenerateUniqueKeyByUserID(Convert.ToInt32(Session["UserID"])); } else { string clientID = string.Empty; string clientSecert = string.Empty; //int companyId = 0; //var company = _IRegisterCompany.FindCompanyByUserId(Convert.ToInt32(Session["UserID"])); //companyId = company.CompanyID; //Generate Keys _IClientKeys.GenerateUniqueKey(out clientID, out clientSecert); //Saving Keys Details in Database clientkeys.ClientKeyID = 0; //clientkeys.CompanyID = companyId; remarks bowo clientkeys.CompanyID = 0; clientkeys.CreateOn = DateTime.Now; clientkeys.ClientID = clientID; clientkeys.ClientSecret = clientSecert; clientkeys.UserID = Convert.ToInt32(Session["UserID"]); _IClientKeys.SaveClientIDandClientSecert(clientkeys); } return(View(clientkeys)); } catch (Exception) { throw; } }
// 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 }); } } }
public string GenerateToken(ClientKey ClientKeys, DateTime IssuedOn) { try { string randomnumber = string.Join(":", new string[] { Convert.ToString(ClientKeys.UserID), KeyGenerator.GetUniqueKey(), Convert.ToString(ClientKeys.CompanyID), Convert.ToString(IssuedOn.Ticks), ClientKeys.ClientID }); return(EncryptionLibrary.EncryptText(randomnumber)); } catch (Exception) { throw; } }
public bool ValidateKeys(ClientKey ClientKeys) { try { var result = (from clientkeys in _context.ClientKeys where clientkeys.ClientID == ClientKeys.ClientID && clientkeys.ClientSecret == ClientKeys.ClientSecret select clientkeys).Count(); if (result > 0) { return(true); } else { return(false); } } catch (Exception) { throw; } }
public static Config GetConfig(this IHostEnvironment environment) { var rootPath = environment.ContentRootPath; var configFile = Path.Combine(rootPath, "Config.json"); if (System.IO.File.Exists(configFile)) { var file = new FileInfo(configFile); if (file.LastWriteTime != configWriteTime) { using (var reader = new StreamReader(configFile)) { config = reader.ReadJson <Config>(); clientKey = config.ClientKey; configWriteTime = file.LastWriteTime; } } } return(config); }
public ActionResult Generate(ClientKey cKey) { try { string clientID = string.Empty; string clientSecert = string.Empty; //Generate Keys _clientKeysRepo.GenerateUniqueKey(out clientID, out clientSecert); cKey.Createdon = DateTime.Now; cKey.ClientId = "100"; cKey.ClientSecret = clientSecert; cKey.UserId = Convert.ToInt32(Session["UserID"]); _clientKeysRepo.UpdateClientIDandClientSecert(cKey); return(View(cKey)); } catch (Exception e) { //Console.WriteLine(e); //throw; return(View()); } }
public int SaveClientIDandClientSecert(ClientKey ClientKeys) { _context.Key.Add(ClientKeys); return(_context.SaveChangesAsync().Result); }
public String ReadValue(String key) { //getting message context with the client name MessageProperties msgProp = OperationContext.Current.IncomingMessageProperties; ContextMessageProperty ctxProperty = msgProp[ContextMessageProperty.Name] as ContextMessageProperty; string clientName = ""; if (ctxProperty.Context.ContainsKey("clientName")) { clientName = ctxProperty.Context["clientName"]; } if (clientName == "") throw new FaultException("ERROR - Client Name not set."); ClientKey ck = new ClientKey(clientName, key); if (!m_serverPairs.ContainsKey(ck)) throw new FaultException("ERROR - Key doesn't exists: " + key); String ret = ""; String address = GetKVS(ck); KVSClient kvs = new KVSClient("KVSService", address); try { ret += kvs.ReadValue(ck); }catch(EndpointNotFoundException) { String temp; m_serverPairs.TryRemove(ck, out temp); throw new FaultException("ERROR - Problem with key: " + key + " | key removed from system"); } return ret; }
public AcquireTokenForClientHandler(Authenticator authenticator, TokenCache tokenCache, string resource, ClientKey clientKey) : base(authenticator, tokenCache, resource, clientKey, TokenSubjectType.Client) { this.SupportADFS = true; }
private String GetKVS(ClientKey ck) { return m_serverPairs[ck]; }
//IBroker public void StorePair(Pair p) { //getting message context with the client name MessageProperties msgProp = OperationContext.Current.IncomingMessageProperties; ContextMessageProperty ctxProperty = msgProp[ContextMessageProperty.Name] as ContextMessageProperty; string clientName = ""; if (ctxProperty.Context.ContainsKey("clientName")) { clientName = ctxProperty.Context["clientName"]; } if(clientName == "") throw new FaultException("ERROR - Client Name not set."); if(m_servers.Count <= 0) throw new FaultException("ERROR - System is down."); ClientKey ck = new ClientKey(clientName, p.Key); if (m_serverPairs.ContainsKey(ck)) throw new FaultException("ERROR - Duplicated key: " + p.Key); String address = GetKVS(); KVSClient kvs = new KVSClient("KVSService", address); try { kvs.StorePair(ck, p.Value); }catch(EndpointNotFoundException) { DeregisterServer(address); StorePair(p); } m_serverPairs.TryAdd(ck, address);//add the key and the server to the list if (!m_servers.ContainsKey(clientName)) m_users.Add(clientName); //Console.WriteLine("Pair Stored in server: " + m_currId); }
internal static void SetDefault(ResourceManagerDbContext context) { var currDate = DateTime.UtcNow; /*----------------------------------------------------------------- * INSERT / UPDATE : Member Resource Manager * ------------------------------------------------------------------*/ var member = new Resource() { Name = "Member Resource", CreateDate = currDate, UpdateDate = currDate, Settings = new ResourceSettings() { Status = ResourceStatus.Live }, Type = ResourceType.Member }; context.Resource.AddOrUpdate(e => e.Name, member); context.SaveChanges(); /*----------------------------------------------------------------- * INSERT / UPDATE : Member Resource Manager Settings * -----------------------------------------------------------------*/ var read = new ResourceClaim() { ResourceId = member.Id, ClaimName = MemberClaim.Read, CreateDate = currDate, UpdateDate = currDate }; var write = new ResourceClaim() { ResourceId = member.Id, ClaimName = MemberClaim.Write, CreateDate = currDate, UpdateDate = currDate }; var create = new ResourceClaim() { ResourceId = member.Id, ClaimName = MemberClaim.Create, CreateDate = currDate, UpdateDate = currDate }; var delete = new ResourceClaim() { ResourceId = member.Id, ClaimName = MemberClaim.Delete, CreateDate = currDate, UpdateDate = currDate }; context.ResourceClaim.AddOrUpdate(e => e.ClaimName, read, write, create, delete); context.SaveChanges(); /*----------------------------------------------------------------- * INSERT / UPDATE : Client Admin * ------------------------------------------------------------------*/ var client = new Client() { Name = "Member Resource Admin Client", OwnerId = 0, CreateDate = currDate, UpdateDate = currDate }; context.Client.AddOrUpdate(e => e.Name, client); context.SaveChanges(); var clientKey = new ClientKey() { ClientId = client.Id, APIKey = "509e567218264608a91aa11213892886", APISecret = "2ed65ad45ca8486a8ff781122e06702f", Status = ClientKeyStatus.Open, CreateDate = currDate, UpdateDate = currDate }; context.ClientKey.AddOrUpdate(e => e.ClientId, clientKey); context.SaveChanges(); /*----------------------------------------------------------------- * INSERT / UPDATE : Client Admin Data Access * ------------------------------------------------------------------*/ var clientDataAccess = new ClientResourceAccess() { ResourceKey = "6132c038ff0146f09a4e2dfab03a28aa", ClientId = client.Id, ResourceId = member.Id, ResourceValue = 0, Status = ClientResourceAccessStatus.Allow, CreateDate = currDate, UpdateDate = currDate }; context.ClientResourceAccess.AddOrUpdate(e => e.ClientId, clientDataAccess); context.SaveChanges(); /*----------------------------------------------------------------- * INSERT / UPDATE : Client Admin Data Access Claims * ------------------------------------------------------------------*/ context.ClientResourceAccessClaim.AddOrUpdate(e => e.ResourceClaimId, new ClientResourceAccessClaim() { ClientResourceAccessId = clientDataAccess.Id, ResourceClaimId = read.Id, Access = ClientResourceClaimsAccess.Allow }, new ClientResourceAccessClaim() { ClientResourceAccessId = clientDataAccess.Id, ResourceClaimId = write.Id, Access = ClientResourceClaimsAccess.Allow }, new ClientResourceAccessClaim() { ClientResourceAccessId = clientDataAccess.Id, ResourceClaimId = create.Id, Access = ClientResourceClaimsAccess.Allow }, new ClientResourceAccessClaim() { ClientResourceAccessId = clientDataAccess.Id, ResourceClaimId = delete.Id, Access = ClientResourceClaimsAccess.Allow }); context.SaveChanges(); }
public IHttpActionResult RegisterDevice([FromUriAttribute(Name = "UserId")] int uid, [FromUriAttribute(Name = "DeviceId")] string did) { try { ClientKey clientkeys = new ClientKey(); // Validating ClientID and ClientSecert already Exists var keyExists = _clientKeys.IsUniqueKeyAlreadyGenerate(uid); if (keyExists) { //// Getting Generate ClientID and ClientSecert Key By UserID var ck = _clientKeys.GetGenerateUniqueKeyByUserID(uid); //if (ck.UserId==cks.UserId && ck.DeviceId == cks.DeviceId) //{ // return Ok<ClientKey>(ck); //} // clientkeys = refreshClient(cks); //if (ck.UserId == uid && ck.DeviceId == did) //{ // return Ok<ClientKey>(ck); //} //else //{ string clientID = string.Empty; string clientSecert = string.Empty; _clientKeys.GenerateUniqueKey(out clientID, out clientSecert); clientkeys.ClientKeyId = ck.ClientKeyId; ck.DeviceId = did; ck.Createdon = DateTime.Now; ck.ClientId = clientID; ck.ClientSecret = clientSecert; ck.UserId = uid; _clientKeys.UpdateClientIDandClientSecert(ck); return(Ok <ClientKey>(ck)); // } //_clientKeys.GenerateUniqueKey(out clientID, out clientSecert); //return Ok<ClientKey>(clientkeys); } else { string clientID = string.Empty; string clientSecert = string.Empty; int deviceId = 0; //Generate Keys _clientKeys.GenerateUniqueKey(out clientID, out clientSecert); //Saving Keys Details in Database clientkeys.ClientKeyId = 0; clientkeys.DeviceId = did; clientkeys.Createdon = DateTime.Now; clientkeys.ClientId = clientID; clientkeys.ClientSecret = clientSecert; clientkeys.UserId = uid; _clientKeys.SaveClientIDandClientSecert(clientkeys); return(Ok <ClientKey>(clientkeys)); } } catch (Exception e) { //Console.WriteLine(e); //throw; return(BadRequest()); } }
public AcquireTokenForClientHandler(Authenticator authenticator, TokenCache tokenCache, string[] scope, ClientKey clientKey) : base(authenticator, tokenCache, scope, clientKey, TokenSubjectType.Client) { this.SupportADFS = false; }
public override int GetHashCode() { return(ClientKey != null?ClientKey.GetHashCode() : 0); }
public AcquireTokenForClientHandler(Authenticator authenticator, TokenCache tokenCache, string resource, ClientKey clientKey) : base(authenticator, tokenCache, resource, clientKey, TokenSubjectType.Client) { this.SupportADFS = true; }
public int UpdateClientIDandClientSecert(ClientKey ClientKeys) { _context.Entry(ClientKeys).State = EntityState.Modified; _context.SaveChanges(); return(_context.SaveChanges()); }
public int SaveClientIDandClientSecert(ClientKey ClientKeys) { _context.ClientKeys.Add(ClientKeys); return(_context.SaveChanges()); }