public async Task <IActionResult> Insert([FromBody] ClientMeta client) { if (string.IsNullOrEmpty(client.ClientId)) { client.ClientId = Guid.NewGuid().ToString(); } if (string.IsNullOrEmpty(client.ClientAllowedGrantTypes)) { return(BadRequest(new ActionResultResponse { Code = -3, Message = "Vui lòng chọn ít nhất 1 quyền truy cập." })); } var result = await _clientRepository.Insert(client); if (result <= 0) { return(BadRequest(new ActionResultResponse { Code = result, Message = result == -1 ? "Tên client đã tồn tại. Vui lòng kiểm tra lại." : "Có gì đó hoạt động chưa đúng. Vui lòng liên hệ với quản trị viên." })); } return(Ok(new ActionResultResponse(result, "Thêm Client thành công."))); }
public static ClientMeta MapClientMeta(Entities.Client contextClient) { Logic.Objects.ClientMeta logicMeta = new ClientMeta() { clientId = contextClient.ClientId, clientName = contextClient.ClientName, clientNickname = contextClient.Nickname, hasAccount = contextClient.HasAccount, isAdmin = contextClient.IsAdmin }; return(logicMeta); }
public static ClientMeta MapClientMeta(HQClient logicHQClient) { Logic.Objects.ClientMeta logicMeta = new ClientMeta() { clientId = logicHQClient.clientID, clientName = logicHQClient.clientName, clientNickname = logicHQClient.nickname, hasAccount = logicHQClient.hasAccount, isAdmin = logicHQClient.isAdmin }; return(logicMeta); }
public static void UseFilterAddIfKeyPoolSizeIsZero() { var metadata = new ClientMeta() { Description = "This is a test of the Nethereum.WalletConnect feature", Icons = new[] { "https://app.warriders.com/favicon.ico" }, Name = "WalletConnect Test", URL = "https://app.warriders.com" }; var connector = new WalletConnect(metadata); Task.WaitAll(connector.Connect()); }
public async Task Execute(string[] args) { var clientMeta = new ClientMeta() { Name = "WalletConnectSharp", Description = "An example that showcases how to use the WalletConnectSharp library", Icons = new [] { "https://app.warriders.com/favicon.ico" }, URL = "https://app.warriders.com/" }; var client = new WalletConnect(clientMeta); Console.WriteLine("Connect using the following URL"); Console.WriteLine(client.URI); await client.Connect(); Console.WriteLine("The account " + client.Accounts[0] + " has connected!"); Console.WriteLine("Using RPC endpoint " + args[0] + " as the fallback RPC endpoint"); var web3 = new Web3(client.CreateProvider(new Uri(args[0]))); var firstAccount = client.Accounts[0]; var secondAccount = args[1]; Console.WriteLine("Sending test transactions from " + firstAccount + " to " + secondAccount); try { await web3.Eth.TransactionManager.SendTransactionAsync(firstAccount, secondAccount, new BigInteger(50).ToHexBigInteger()); } catch (Exception e) { Console.WriteLine(e); } try { await web3.Eth.TransactionManager.SendTransactionAsync(firstAccount, secondAccount, new BigInteger(50).ToHexBigInteger()); } catch (Exception e) { Console.WriteLine(e); } await client.Disconnect(); }
public WalletConnect(ClientMeta clientMeta, ITransport transport = null, ICipher cipher = null, int?chainId = 1, string bridgeUrl = "https://bridge.walletconnect.org", EventDelegator eventDelegator = null ) { if (eventDelegator == null) { eventDelegator = new EventDelegator(); } this.Events = eventDelegator; this.ClientMetadata = clientMeta; this.ChainId = chainId; if (bridgeUrl.StartsWith("https")) { bridgeUrl = bridgeUrl.Replace("https", "wss"); } else if (bridgeUrl.StartsWith("http")) { bridgeUrl = bridgeUrl.Replace("http", "ws"); } var topicGuid = Guid.NewGuid(); _handshakeTopic = topicGuid.ToString(); clientId = Guid.NewGuid().ToString(); if (transport == null) { transport = new WebsocketTransport(eventDelegator); } this._bridgeUrl = bridgeUrl; this.Transport = transport; if (cipher == null) { cipher = new AESCipher(); } this.Cipher = cipher; GenerateKey(); }
/// <summary> /// Maps a context relationship to a relationship meta /// </summary> /// <param name="contextRecipientXref"></param> /// <returns></returns> public static Logic.Objects.RelationshipMeta MapRelationshipMeta(Data.Entities.ClientRelationXref contextXrefRelationship, Guid clientIDMetaToMap) { List <ClientTagXref> tagXrefList = contextXrefRelationship.SenderClientId != clientIDMetaToMap?contextXrefRelationship.RecipientClient.ClientTagXref.ToList() : contextXrefRelationship.SenderClient.ClientTagXref.ToList(); ClientMeta logicMeta = contextXrefRelationship.SenderClientId != clientIDMetaToMap?Mapper.MapClientMeta(contextXrefRelationship.RecipientClient) : Mapper.MapClientMeta(contextXrefRelationship.SenderClient); Logic.Objects.RelationshipMeta logicRelationship = new RelationshipMeta() { relationshipClient = logicMeta, eventType = Mapper.MapEvent(contextXrefRelationship.EventType), clientRelationXrefID = contextXrefRelationship.ClientRelationXrefId, tags = tagXrefList.Select(Mapper.MapTagRelationXref).OrderBy(t => t.tagName).ToList(), assignmentStatus = MapAssignmentStatus(contextXrefRelationship.AssignmentStatus), removable = contextXrefRelationship.ChatMessage.Count > 0 ? false : true }; return(logicRelationship); }
private static Client MapToClient(ClientMeta clientMeta) { var client = new Client { ClientId = clientMeta.ClientId, IdentityTokenLifetime = clientMeta.IdentityTokenLifetime, ClientName = clientMeta.ClientName, AbsoluteRefreshTokenLifetime = clientMeta.AbsoluteRefreshTokenLifetime, AccessTokenLifetime = clientMeta.AccessTokenLifetime, AccessTokenType = clientMeta.AccessTokenType, AllowAccessTokensViaBrowser = clientMeta.AllowAccessTokensViaBrowser, AllowOfflineAccess = clientMeta.AllowOfflineAccess, AllowPlainTextPkce = clientMeta.AllowPlainTextPkce, AllowRememberConsent = clientMeta.AllowRememberConsent, AlwaysIncludeUserClaimsInIdToken = clientMeta.AlwaysIncludeUserClaimsInIdToken, AlwaysSendClientClaims = clientMeta.AlwaysSendClientClaims, AuthorizationCodeLifetime = clientMeta.AuthorizationCodeLifetime, BackChannelLogoutSessionRequired = clientMeta.BackChannelLogoutSessionRequired, BackChannelLogoutUri = clientMeta.BackChannelLogoutUri, ClientClaimsPrefix = clientMeta.ClientClaimsPrefix, ClientUri = clientMeta.ClientUri, ConsentLifetime = clientMeta.ConsentLifetime, EnableLocalLogin = clientMeta.EnableLocalLogin, Enabled = clientMeta.Enabled, FrontChannelLogoutSessionRequired = clientMeta.FrontChannelLogoutSessionRequired, FrontChannelLogoutUri = clientMeta.FrontChannelLogoutUri, IncludeJwtId = clientMeta.IncludeJwtId, LogoUri = clientMeta.LogoUri, ClientAllowedGrantTypes = clientMeta.ClientAllowedGrantTypes, PairWiseSubjectSalt = clientMeta.PairWiseSubjectSalt, ProtocolType = clientMeta.ProtocolType, RefreshTokenExpiration = clientMeta.RefreshTokenExpiration, RefreshTokenUsage = clientMeta.RefreshTokenUsage, RequireClientSecret = clientMeta.RequireClientSecret, RequireConsent = clientMeta.RequireConsent, RequirePkce = clientMeta.RequirePkce, SlidingRefreshTokenLifetime = clientMeta.SlidingRefreshTokenLifetime, UpdateAccessTokenClaimsOnRefresh = clientMeta.UpdateAccessTokenClaimsOnRefresh, UnsignName = clientMeta.ClientName.StripVietnameseChars() }; return(client); }
public async Task <int> Insert(ClientMeta clientMeta) { var isExists = await CheckNameExists(clientMeta.ClientId, clientMeta.ClientName); if (isExists) { return(-1); } var client = MapToClient(clientMeta); using (var transaction = Context.Database.BeginTransaction()) { client.ProtocolType = IdentityServerConstants.ProtocolTypes.OpenIdConnect; _clientRepository.Create(client); var result = await Context.SaveChangesAsync(); if (result <= 0) { transaction.Rollback(); return(result); } // Insert client post logout redirect uri. if (!string.IsNullOrEmpty(clientMeta.ClientPostLogoutRedirectUris)) { var listClientPostLogoutRedirectUris = clientMeta.ClientPostLogoutRedirectUris.Split(','); if (listClientPostLogoutRedirectUris.Any()) { var clientPostLogoutRedirectUris = MapToPostLogoutRedirectUris(clientMeta.ClientId, listClientPostLogoutRedirectUris); foreach (var clientPostLogoutRedirectUri in clientPostLogoutRedirectUris) { await _clientPostLogoutRedirectUrisRepository.Insert(clientPostLogoutRedirectUri); } } } // Insert client redirect uri. if (!string.IsNullOrEmpty(clientMeta.ClientPostLogoutRedirectUris)) { var listClientPostLogoutRedirectUris = clientMeta.ClientPostLogoutRedirectUris.Split(','); if (listClientPostLogoutRedirectUris.Any()) { var clientRedirectUris = MapToClientRedirectUris(clientMeta.ClientId, listClientPostLogoutRedirectUris); foreach (var clientRedirectUri in clientRedirectUris) { await _clientRedirectUrisRepository.Insert(clientRedirectUri); } } } // Insert client secret. if (!string.IsNullOrEmpty(clientMeta.ClientSecret)) { var listClientSecret = clientMeta.ClientSecret.Split(','); if (listClientSecret.Any()) { var clientSecrets = MapToClientSecret(clientMeta.ClientId, listClientSecret); foreach (var clientSecret in clientSecrets) { await _clientSecretRepository.Insert(clientSecret); } } } if (!string.IsNullOrEmpty(clientMeta.ClientAllowedScopes)) { var listClientAllowedScopes = clientMeta.ClientAllowedScopes.Split(','); if (listClientAllowedScopes.Any()) { var clientAllowedScopes = MapToClientAllowedScope(clientMeta.ClientId, listClientAllowedScopes); foreach (var clientAllowedScope in clientAllowedScopes) { await _clientAllowedScopesRepository.Insert(clientAllowedScope); } } } transaction.Commit(); return(result); } }
public static void Initialize(IServiceProvider serviceProvider) { var clientRepository = serviceProvider.GetService <IClientRepository>(); var context = serviceProvider.GetRequiredService <CoreDbContext>(); context.Database.EnsureCreated(); var seedId = Guid.NewGuid().ToString(); var defaultUserRoleId = Guid.NewGuid().ToString(); #region Tenant. if (!context.Set <Tenant>().Any()) { context.Set <Tenant>().Add(new Tenant(seedId, "Công ty cổ phần GHMSoft", "*****@*****.**", "01683285041", "Thái Thịnh - Đống Đa - Hà Nội", true, string.Empty, string.Empty)); context.SaveChanges(); } #endregion #region Roles if (!context.Set <Role>().Any()) { context.Set <Role>().Add(new Role("SuperAdministrator", "SuperAdministrator", "SuperAdministrator", seedId, Guid.NewGuid().ToString())); context.Set <Role>().Add(new Role(seedId, "Administrator", "Administrator", seedId, Guid.NewGuid().ToString())); context.Set <Role>().Add(new Role(defaultUserRoleId, "Default", "Default", defaultUserRoleId, Guid.NewGuid().ToString())); context.SaveChanges(); } #endregion #region UserAccounts. if (!context.Set <UserAccount>().Any()) { var passwordSalt = Generate.GenerateRandomBytes(Generate.PasswordSaltLength); var passwordHash = Generate.GetInputPasswordHash("123456", passwordSalt); var userAccount = new UserAccount { Id = seedId, FullName = "Nguyễn Huy Hoàng", UserName = "******", Email = "*****@*****.**", PhoneNumber = "01683285041", IsActive = true, PasswordSalt = passwordSalt, PasswordHash = Convert.ToBase64String(passwordHash), ConcurrencyStamp = Guid.NewGuid().ToString(), NormalizedUserName = "******".ToUpper(), TenantId = seedId }; context.Set <UserAccount>().Add(userAccount); context.SaveChanges(); } #endregion #region UserRole. if (!context.Set <IdentityUserRole <string> >().Any()) { var userRole = new IdentityUserRole <string> { UserId = seedId, RoleId = "SuperAdministrator" }; context.Set <IdentityUserRole <string> >().Add(userRole); context.SaveChanges(); } #endregion #region ApiResource. if (!context.Set <ApiResource>().Any()) { context.Set <ApiResource>().Add(new ApiResource("GHM_Core_Api", "GHM_Core_Api", "GHMSoft core api", true)); context.Set <ApiResource>().Add(new ApiResource("GHM_Hr_Api", "GHM_Hr_Api", "GHMSoft hr api", true)); context.Set <ApiResource>().Add(new ApiResource("GHM_Timekeeping_Api", "GHM_Timekeeping_Api", "GHMSoft timekeeping api", true)); context.SaveChanges(); } #endregion #region Client. if (!context.Set <Client>().Any()) { var angularAppId = "a3a3b45c-3665-44b2-931a-f840fdfca572"; var hrAppId = "c3e86dc7-0417-4a2d-88f7-ef1454e5b1ff"; var coreAppId = "6755623e-4d06-4b58-a383-1f8ef66a9094"; var client = new ClientMeta { ClientId = angularAppId, ClientName = "GHMSoft Application", ClientAllowedGrantTypes = "ResourceOwnerPassword", AllowOfflineAccess = true, RequireConsent = false, RequireClientSecret = false, ClientAllowedScopes = "GHM_Core_Api, GHM_Hr_Api, GHM_Timekeeping_Api", }; var clientHr = new ClientMeta { ClientId = hrAppId, ClientName = "GHMSoft HR Api", ClientAllowedGrantTypes = "ClientCredentials", AllowOfflineAccess = true, RequireConsent = false, RequireClientSecret = false, ClientAllowedScopes = "GHM_Core_Api, GHM_Hr_Api, GHM_Timekeeping_Api", }; var clientCore = new ClientMeta { ClientId = coreAppId, ClientName = "GHMSoft Core Api", ClientAllowedGrantTypes = "ClientCredentials", AllowOfflineAccess = true, RequireConsent = false, RequireClientSecret = false, ClientAllowedScopes = "GHM_Core_Api, GHM_Hr_Api, GHM_Timekeeping_Api", }; var result = Task.Run(() => clientRepository.Insert(client)).Result; var result1 = Task.Run(() => clientRepository.Insert(clientHr)).Result; var result2 = Task.Run(() => clientRepository.Insert(clientCore)).Result; } #endregion #region Language if (!context.Set <Language>().Any()) { var defaultLanguage = new Language { Id = "vi-VN", Description = "Ngôn ngữ Tiếng Việt.", Name = "Tiếng Việt", IsActive = true }; context.Set <Language>().Add(defaultLanguage); context.Set <Language>().Add(new Language { Id = "en-US", Description = "English (United State)", Name = "English (United State)", IsActive = true }); context.Set <Language>().Add(new Language { Id = "en-UK", Description = "English (United Kingdom)", Name = "English (United Kingdom)", IsActive = true }); var result = context.SaveChanges(); if (result > 0) { // Add default language for tenant. context.Set <TenantLanguage>() .Add(new TenantLanguage { TenantId = seedId, Name = defaultLanguage.Name, IsActive = defaultLanguage.IsActive, LanguageId = defaultLanguage.Id }); context.SaveChanges(); } } #endregion }
public WalletConnect(ClientMeta clientMeta, ITransport transport = null, ICipher cipher = null, int?chainId = 1, string bridgeUrl = "https://bridge.walletconnect.org", EventDelegator eventDelegator = null ) { if (clientMeta == null) { throw new ArgumentException("clientMeta cannot be null!"); } if (string.IsNullOrWhiteSpace(clientMeta.Description)) { throw new ArgumentException("clientMeta must include a valid Description"); } if (string.IsNullOrWhiteSpace(clientMeta.Name)) { throw new ArgumentException("clientMeta must include a valid Name"); } if (string.IsNullOrWhiteSpace(clientMeta.URL)) { throw new ArgumentException("clientMeta must include a valid URL"); } if (clientMeta.Icons == null || clientMeta.Icons.Length == 0) { throw new ArgumentException("clientMeta must include an array of Icons the Wallet app can use. These Icons must be URLs to images. You must include at least one image URL to use"); } if (eventDelegator == null) { eventDelegator = new EventDelegator(); } this.Events = eventDelegator; this.ClientMetadata = clientMeta; this.ChainId = chainId; if (bridgeUrl.StartsWith("https")) { bridgeUrl = bridgeUrl.Replace("https", "wss"); } else if (bridgeUrl.StartsWith("http")) { bridgeUrl = bridgeUrl.Replace("http", "ws"); } var topicGuid = Guid.NewGuid(); _handshakeTopic = topicGuid.ToString(); clientId = Guid.NewGuid().ToString(); if (transport == null) { transport = new WebsocketTransport(eventDelegator); } this._bridgeUrl = bridgeUrl; this.Transport = transport; if (cipher == null) { cipher = new AESCipher(); } this.Cipher = cipher; GenerateKey(); }