private void TryRunUpgradeScript(ConfigurationDbContext configurationContext) { try { // If there are no api resources we can assume that this is the first start after the upgrade and run the upgrade script. string upgradeScript = LoadUpgradeScript(); configurationContext.Database.ExecuteSqlCommand(upgradeScript); // All client secrets must be hashed otherwise the identity server validation will fail. var allClients = Enumerable.ToList(configurationContext.Clients.Include(client => client.ClientSecrets)); foreach (var client in allClients) { foreach (var clientSecret in client.ClientSecrets) { clientSecret.Value = HashExtensions.Sha256(clientSecret.Value); } client.AccessTokenLifetime = Configurations.DefaultAccessTokenExpiration; client.AbsoluteRefreshTokenLifetime = Configurations.DefaultRefreshTokenExpiration; } configurationContext.SaveChanges(); } catch (Exception ex) { // Probably the upgrade script was already executed and we don't need to do anything. } }
public void ReadTag(string path, bool readMediaProperties = true, bool readCoverArt = true, HashType hashType = HashType.None) { Path = path; HashType = hashType; _fileTag = TagLib.File.Create(Path); if (readMediaProperties) { using (var file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { Size = file.Length; } DateCreated = _useUtc ? System.IO.File.GetCreationTimeUtc(path) : System.IO.File.GetCreationTime(path); DateModified = _useUtc ? System.IO.File.GetLastWriteTimeUtc(path) : System.IO.File.GetLastWriteTime(path); ReadMediaProperties(); } if (readCoverArt) { ReadCoverArt(); } if (hashType != HashType.None) { Hash = HashExtensions.GetFileHash(path, HashType); } }
public async Task AddOrUpdateWithSecret(ClientInput value, String secret) { var clientSecret = HashExtensions.Sha256(secret); var existing = await SelectFullEntity().Where(i => i.ClientId == value.ClientId).FirstOrDefaultAsync(); if (existing == null) { var entity = mapper.Map <Client>(value); entity.ClientSecrets = new List <ClientSecret>() { new ClientSecret() { Secret = clientSecret, } }; configDb.Clients.Add(entity); } else { mapper.Map <ClientInput, Client>(value, existing); existing.ClientSecrets.Clear(); existing.ClientSecrets.Add(new ClientSecret() { Secret = clientSecret }); configDb.Clients.Update(existing); } await configDb.SaveChangesAsync(); }
public object Validar(ValidarAmbienteInModel model) { model.Validate(); var ambienteFiltro = new Ambiente { Codigo = model.Ambiente }; var ambiente = _ambienteRepository.GetById(ambienteFiltro); Check.NotEmpty(ambiente?.Codigo, _mensagemAmbienteNaoCadastrado); var usuarioFiltro = new Usuario { Nm_Login = model.Login }; var usuario = _usuarioRepository.GetById(usuarioFiltro); Check.NotEmpty(usuario?.Nm_Usuario, _mensagemUsuarioNaoCadastrado); var senhaHash = HashExtensions.GetHash(model.Login, model.Senha); var senhaMd5 = Md5Extensions.GetMd5(senhaHash); Check.That(!Md5Extensions.IsValidMd5(senhaHash, senhaMd5), nameof(senhaHash), _mensagemSenhaNaoCadastrada); // provisorio //var ambiente = new Ambiente(); var token = new Token(ambiente, true).GetToken(); return(new ValidarAmbienteOutModel { Ambiente = null, Token = token, }); }
public double SimilarityTo(Hash other) { double similarity = HashExtensions.Similarity(PerceptualHashValue, other.PerceptualHashValue); Logging.LogVerbose($"Hash similarity {PerceptualHash} vs {other.PerceptualHash} = {similarity:P1} ({PerceptualHashValue} v {other.PerceptualHashValue})"); return(similarity); }
public async Task <string> GetSession() { var cache = _file.GetCacheFolder(Game.Osrs); var file = Path.Join(cache, "misc_new"); var text = File.Exists(file) ? await File.ReadAllTextAsync(file) : null; return(string.IsNullOrEmpty(text) ? null : Encoding.Default.GetString(HashExtensions.Xor(text, GetKey()))); }
public async Task WriteSession(string session) { var cache = _file.GetCacheFolder(Game.Osrs); var cacheInu = _file.GetCacheFolder(Game.Rs3); var file = Path.Join(cache, "misc_new"); var fileInu = Path.Join(cacheInu, "misc_new"); var xor = HashExtensions.Xor(session, GetKey()); await File.WriteAllBytesAsync(file, xor); await File.WriteAllBytesAsync(fileInu, xor); }
protected override ValueTask <bool> ValidateClientSecretAsync(string secret, string comparand, CancellationToken cancellationToken = default) { //Constant time comparisons here are important. Otherwise the secrets can be guessed. var hashed = HashExtensions.Sha256(secret); var hashedBytes = Encoding.UTF8.GetBytes(hashed); var comparendBytes = Encoding.UTF8.GetBytes(comparand); var equal = CryptographicOperations.FixedTimeEquals(hashedBytes, comparendBytes); return(ValueTask.FromResult(equal)); }
public EmailMessage CreateTextEmail(string textTemplate, dynamic model) { var hash = HashExtensions.FromDynamic(model); var textBody = PrepareBodyFromTemplate(textTemplate, hash); var wrapped = WrapEmail(hash); var email = new EmailMessage { From = wrapped.From, To = wrapped.To, Subject = wrapped.Subject, TextBody = textBody }; return(email); }
public static IEnumerable <ApiResource> GetApis(IConfiguration configuration) { var apiList = configuration.GetSection("InitialData:Apis").Get <IEnumerable <ApiResource> >() ?? Array.Empty <ApiResource>(); foreach (var api in apiList) { foreach (var secret in api.ApiSecrets.Where(s => s.Type == IdentityServerConstants.SecretTypes.SharedSecret)) { secret.Value = HashExtensions.Sha256(secret.Value); } yield return(api); } }
public static IEnumerable <Client> GetClients(IConfiguration configuration) { var clientList = configuration.GetSection("InitialData:Clients").Get <IEnumerable <Client> >() ?? Array.Empty <Client>(); foreach (var client in clientList) { foreach (var secret in client.ClientSecrets.Where(s => s.Type == IdentityServerConstants.SecretTypes.SharedSecret)) { secret.Value = HashExtensions.Sha256(secret.Value); } yield return(client); } }
public static IEnumerable <Client> GetClients() { return(new List <Client> { new Client { ClientId = "mvc", AllowedGrantTypes = GrantTypes.Implicit, ClientSecrets = { new Secret("secret", HashExtensions.Sha256("secret")) }, AllowedCorsOrigins = { "api1" } } }); }
public string ForgotPassword(string emailAddress) { var user = _usersTable.SingleOrDefault(u => u.UserEmailAddress == emailAddress); if (user != null) { var userString = string.Format("{0}-{1}-{2}-{3}", user.UserName, user.Password, user.UserEmailAddress, DateTime.Now.ToString()); var verificationCode = HashExtensions.GetMD5Hash(userString); user.ActivationKey = verificationCode; context.SubmitChanges(); return(verificationCode); } return(string.Empty); }
public async Task SetClientSecret(int id, String secretString) { var client = await GetFullClientEntity(id); if (client == null) { throw new InvalidOperationException($"Cannot find a client to add a secret to with id {id}."); } var secret = HashExtensions.Sha256(secretString); client.ClientSecrets.Clear(); client.ClientSecrets.Add(new ClientSecret() { Secret = secret }); configDb.Clients.Update(client); await configDb.SaveChangesAsync(); }
public ActionResult Add(NewUserModel newUserModel) { var urlFormat = string.Empty; var createStatus = true; if (ModelState.IsValid) { var userActivationKey = HashExtensions.GetMD5Hash(string.Format("{0}-{1}-{2}", newUserModel.UserDisplayName, newUserModel.UserEmailAddress, DateTime.Now)); createStatus = _userRepository.AddUser(newUserModel.UserEmailAddress, newUserModel.UserDisplayName, userActivationKey); if (createStatus) { var newUser = _userRepository.GetUserNameByEmail(newUserModel.UserEmailAddress); _roleRepository.AddRoleForUser(newUser.UserID, newUserModel.RoleId); urlFormat = string.Format("{0}account/register?newUserTicket={1}", GetRootUrl(), userActivationKey); var status = Emailer.SendMessage(SettingsRepository.BlogAdminEmailAddress, newUserModel.UserEmailAddress, string.Format("Join {0}", SettingsRepository.BlogName), string.Format(NewUserEmailMeassage, newUserModel.UserDisplayName, SettingsRepository.BlogName, urlFormat, SettingsRepository.BlogName)); if (status) { return(RedirectToRoute("AdminUserManagement")); } } } newUserModel.Title = SettingsRepository.BlogName; var errorMessage = createStatus ? "Unable to send an email because the emailing service failed. Please send the following url to the user " + urlFormat : "Creation/update of new user failed. Check the email address entered."; ModelState.AddModelError("", errorMessage); return(View(newUserModel)); }
public async Task Run(String appDashboardHost, String clientSecretFile) { ClientSecret secret = null; if (clientSecretFile != null) { var secretString = AddFromMetadataToolController.TrimNewLine(File.ReadAllText(clientSecretFile)); secret = new ClientSecret() { Secret = HashExtensions.Sha256(secretString) }; logger.LogInformation($"Updating app dashboard to host '{appDashboardHost}' with secret from '{clientSecretFile}'."); } else { secret = new ClientSecret() { Secret = appConfig.DefaultSecret.Sha256() }; logger.LogWarning($"Adding App dashboard '{appDashboardHost}' with default secret. This is not suitable for production deployments."); } var redirectUri = $"https://{appDashboardHost}/signin-oidc"; var logoutUri = $"https://{appDashboardHost}/signout-callback-oidc"; var clientEntity = await configContext.Clients .Include(i => i.RedirectUris) .Include(i => i.AllowedScopes) .Include(i => i.ClientSecrets) .FirstOrDefaultAsync(i => i.ClientId == "AppDashboard"); if (clientEntity != null) { clientEntity.LogoutUri = logoutUri; clientEntity.RedirectUris = clientEntity.RedirectUris ?? new List <ClientRedirectUri>(); if (clientEntity.RedirectUris.Count == 0) { clientEntity.RedirectUris.Add(new ClientRedirectUri()); } clientEntity.RedirectUris[0].Uri = redirectUri; clientEntity.ClientSecrets = clientEntity.ClientSecrets ?? new List <ClientSecret>(); if (clientEntity.ClientSecrets.Count == 0) { clientEntity.ClientSecrets.Add(new ClientSecret()); } clientEntity.ClientSecrets[0].Secret = secret.Secret; } else { var client = new Client { ClientId = "AppDashboard", Name = "App Dashboard", AllowedGrantTypes = EntityFramework.Entities.GrantTypes.Hybrid, ClientSecrets = new List <ClientSecret> { secret }, AllowedScopes = new List <ClientScope> { new ClientScope() { Scope = StandardScopes.OpenId }, new ClientScope() { Scope = StandardScopes.Profile }, new ClientScope() { Scope = StandardScopes.OfflineAccess }, new ClientScope() { Scope = "Threax.IdServer" }, }, RedirectUris = new List <ClientRedirectUri>() { new ClientRedirectUri() { Uri = redirectUri } }, LogoutUri = logoutUri }; configContext.Clients.Add(client); } var scope = await configContext.Scopes.FirstOrDefaultAsync(i => i.Name == "Threax.IdServer"); if (scope != null) { scope.DisplayName = "Threax.IdServer"; } else { scope = new Scope() { Name = "Threax.IdServer", DisplayName = "Threax.IdServer" }; configContext.Scopes.Add(scope); } await configContext.SaveChangesAsync(); if (clientSecretFile != null) { logger.LogInformation($"Set app dashboard to host '{appDashboardHost}' with secret from '{clientSecretFile}'."); } else { logger.LogWarning($"Set app dashboard '{appDashboardHost}' with default secret. This is not suitable for production deployments."); } }
private static void CreateOrUpdateTheApiResources() { var options = new DbContextOptions <ConfigurationDbContext>(); var storeOptions = new ConfigurationStoreOptions(); var files = GetFiles("Database/ApiResources"); foreach (var file in files) { var jToken = JToken.Parse(File.ReadAllText(file.FullName)); try { dynamic dynObject = ConvertJTokenToObject(jToken); using (var ctx = new ConfigurationDbContext(options, storeOptions)) { string apiResourceName = dynObject.Name.ToString(); var apiResource = ctx.ApiResources .Include(x => x.Secrets) .Include(x => x.Scopes) .Include(x => x.UserClaims) .FirstOrDefault(x => x.Name == apiResourceName); if (apiResource == null) { apiResource = new Data.EntityFramework.Entities.ApiResource(); ctx.ApiResources.Add(apiResource); } apiResource.Name = dynObject.Name.ToString(); apiResource.DisplayName = dynObject.DisplayName.ToString(); apiResource.Description = dynObject.Description.ToString(); apiResource.Enabled = StringExtensions.ToBoolean(dynObject.Enabled.ToString()); #region Secrets if (apiResource.Secrets != null) { apiResource.Secrets.RemoveAll(x => true); } else { apiResource.Secrets = new List <ApiSecret>(); } if (dynObject.Secrets != null) { foreach (var apiSecret in dynObject.Secrets) { DateTime?expiration = null; if (!string.IsNullOrEmpty(apiSecret.Expiration)) { expiration = DateTime.Parse(apiSecret.Expiration.ToString()); } apiResource.Secrets.Add(new ApiSecret() { ApiResource = apiResource, Description = apiSecret.Description.ToString(), Expiration = expiration, Type = apiSecret.Type, Value = HashExtensions.Sha256(apiSecret.Value) }); } } #endregion #region Scopes if (apiResource.Scopes != null) { apiResource.Scopes.RemoveAll(x => true); } else { apiResource.Scopes = new List <ApiScope>(); } apiResource.Scopes.Add(new ApiScope() { ApiResource = apiResource, Name = apiResource.Name, Required = false, DisplayName = apiResource.DisplayName }); if (dynObject.Scopes != null) { foreach (var apiScope in dynObject.Scopes) { var userClaims = new List <ApiScopeClaim>(); foreach (var userClaim in apiScope.UserClaims) { userClaims.Add(new ApiScopeClaim() { ApiScope = apiScope, Type = userClaim }); } apiResource.Scopes.Add(new ApiScope() { ApiResource = apiResource, Name = apiScope.Name.ToString(), Description = apiScope.Description.ToString(), DisplayName = apiScope.DisplayName.ToString(), Emphasize = StringExtensions.ToBoolean(apiScope.Emphasize.ToString()), Required = StringExtensions.ToBoolean(apiScope.Required.ToString()), ShowInDiscoveryDocument = StringExtensions.ToBoolean(apiScope.ShowInDiscoveryDocument.ToString()), UserClaims = userClaims }); } } #endregion #region UserClaims if (apiResource.UserClaims != null) { apiResource.UserClaims.RemoveAll(x => true); } else { apiResource.UserClaims = new List <ApiResourceClaim>(); } if (dynObject.UserClaims != null) { foreach (var apiResourceClaim in dynObject.UserClaims) { apiResource.UserClaims.Add(new ApiResourceClaim() { ApiResource = apiResource, Type = apiResourceClaim }); } } #endregion ctx.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex); } } }
private static void CreateOrUpdateTheClients() { var options = new DbContextOptions <ConfigurationDbContext>(); var storeOptions = new ConfigurationStoreOptions(); var clientFiles = GetFiles("Database/Clients"); foreach (var clientFile in clientFiles) { var jToken = JToken.Parse(File.ReadAllText(clientFile.FullName)); try { dynamic dynObject = ConvertJTokenToObject(jToken); using (var ctx = new ConfigurationDbContext(options, storeOptions)) { string clientName = dynObject.ClientName.ToString(); var client = ctx.Clients .Include(x => x.Claims) .Include(x => x.AllowedCorsOrigins) .Include(x => x.AllowedGrantTypes) .Include(x => x.IdentityProviderRestrictions) .Include(x => x.AllowedScopes) .Include(x => x.ClientSecrets) .Include(x => x.RedirectUris) .Include(x => x.PostLogoutRedirectUris) .FirstOrDefault(x => x.ClientName == clientName); if (client == null) { client = new Client(); ctx.Clients.Add(client); } client.AbsoluteRefreshTokenLifetime = StringExtensions.ToInt32(dynObject.AbsoluteRefreshTokenLifetime.ToString()); client.AccessTokenLifetime = StringExtensions.ToInt32(dynObject.AccessTokenLifetime.ToString()); client.AccessTokenType = StringExtensions.ToInt32(dynObject.AccessTokenType.ToString()); client.AllowAccessTokensViaBrowser = StringExtensions.ToBoolean(dynObject.AllowAccessTokensViaBrowser.ToString()); client.AllowOfflineAccess = StringExtensions.ToBoolean(dynObject.AllowOfflineAccess.ToString()); client.AllowPlainTextPkce = StringExtensions.ToBoolean(dynObject.AllowPlainTextPkce.ToString()); client.AllowRememberConsent = StringExtensions.ToBoolean(dynObject.AllowRememberConsent.ToString()); client.AlwaysIncludeUserClaimsInIdToken = StringExtensions.ToBoolean(dynObject.AlwaysIncludeUserClaimsInIdToken.ToString()); client.AlwaysSendClientClaims = StringExtensions.ToBoolean(dynObject.AlwaysSendClientClaims.ToString()); client.AuthorizationCodeLifetime = StringExtensions.ToInt32(dynObject.AuthorizationCodeLifetime.ToString()); client.ClientId = dynObject.ClientId.ToString(); client.ClientName = dynObject.ClientName.ToString(); client.ClientUri = dynObject.ClientUri.ToString(); client.EnableLocalLogin = StringExtensions.ToBoolean(dynObject.EnableLocalLogin.ToString()); client.Enabled = StringExtensions.ToBoolean(dynObject.Enabled.ToString()); client.IdentityTokenLifetime = StringExtensions.ToInt32(dynObject.IdentityTokenLifetime.ToString()); client.IncludeJwtId = StringExtensions.ToBoolean(dynObject.IncludeJwtId.ToString()); client.LogoUri = dynObject.LogoUri.ToString(); client.LogoutSessionRequired = StringExtensions.ToBoolean(dynObject.LogoutSessionRequired.ToString()); client.LogoutUri = dynObject.LogoutUri.ToString(); client.PrefixClientClaims = StringExtensions.ToBoolean(dynObject.PrefixClientClaims.ToString()); client.ProtocolType = dynObject.ProtocolType.ToString(); client.RefreshTokenExpiration = StringExtensions.ToInt32(dynObject.RefreshTokenExpiration.ToString()); client.RefreshTokenUsage = StringExtensions.ToInt32(dynObject.RefreshTokenUsage.ToString()); client.RequireClientSecret = StringExtensions.ToBoolean(dynObject.RequireClientSecret.ToString()); client.RequireConsent = StringExtensions.ToBoolean(dynObject.RequireConsent.ToString()); client.RequirePkce = StringExtensions.ToBoolean(dynObject.RequirePkce.ToString()); client.SlidingRefreshTokenLifetime = StringExtensions.ToInt32(dynObject.SlidingRefreshTokenLifetime.ToString()); client.UpdateAccessTokenClaimsOnRefresh = StringExtensions.ToBoolean(dynObject.UpdateAccessTokenClaimsOnRefresh.ToString()); #region ClientClaims if (client.Claims != null) { client.Claims.RemoveAll(x => true); } else { client.Claims = new List <ClientClaim>(); } if (dynObject.ClientClaim != null) { foreach (var claim in dynObject.ClientClaim) { client.Claims.Add(new ClientClaim() { Client = client, Type = claim.Type, Value = claim.Value }); } } #endregion #region AllowedCorsOrigins if (client.AllowedCorsOrigins != null) { client.AllowedCorsOrigins.RemoveAll(x => true); } else { client.AllowedCorsOrigins = new List <ClientCorsOrigin>(); } if (dynObject.ClientCorsOrigin != null) { foreach (var allowedCorsOrigin in dynObject.ClientCorsOrigin) { client.AllowedCorsOrigins.Add(new ClientCorsOrigin() { Client = client, Origin = allowedCorsOrigin }); } } #endregion #region ClientGrantTypes if (client.AllowedGrantTypes != null) { client.AllowedGrantTypes.RemoveAll(x => true); } else { client.AllowedGrantTypes = new List <ClientGrantType>(); } if (dynObject.AllowedGrantTypes != null) { foreach (var allowedGrantType in dynObject.AllowedGrantTypes) { client.AllowedGrantTypes.Add(new ClientGrantType() { Client = client, GrantType = allowedGrantType }); } } #endregion #region ClientIdPRestriction if (client.IdentityProviderRestrictions != null) { client.IdentityProviderRestrictions.RemoveAll(x => true); } else { client.IdentityProviderRestrictions = new List <ClientIdPRestriction>(); } if (dynObject.IdentityProviderRestrictions != null) { foreach (var provider in dynObject.IdentityProviderRestrictions) { client.IdentityProviderRestrictions.Add(new ClientIdPRestriction() { Client = client, Provider = provider }); } } #endregion #region PostLogout RedirectUris if (client.PostLogoutRedirectUris != null) { client.PostLogoutRedirectUris.RemoveAll(x => true); } else { client.PostLogoutRedirectUris = new List <ClientPostLogoutRedirectUri>(); } if (dynObject.PostLogoutRedirectUris != null) { foreach (var redirectUri in dynObject.PostLogoutRedirectUris) { client.PostLogoutRedirectUris.Add(new ClientPostLogoutRedirectUri() { Client = client, PostLogoutRedirectUri = redirectUri }); } } #endregion #region Redirect Uris if (client.RedirectUris != null) { client.RedirectUris.RemoveAll(x => true); } else { client.RedirectUris = new List <ClientRedirectUri>(); } if (dynObject.RedirectUris != null) { foreach (var redirectUri in dynObject.RedirectUris) { client.RedirectUris.Add(new ClientRedirectUri() { Client = client, RedirectUri = redirectUri }); } } #endregion #region Allowed scopes if (client.AllowedScopes != null) { client.AllowedScopes.RemoveAll(x => true); } else { client.AllowedScopes = new List <ClientScope>(); } if (dynObject.AllowedScopes != null) { foreach (var allowedScope in dynObject.AllowedScopes) { client.AllowedScopes.Add(new ClientScope() { Client = client, Scope = allowedScope }); } } #endregion #region Client Secrets if (client.ClientSecrets != null) { client.ClientSecrets.RemoveAll(x => true); } else { client.ClientSecrets = new List <ClientSecret>(); } if (dynObject.ClientSecrets != null) { foreach (var clientSecret in dynObject.ClientSecrets) { DateTime?expiration = null; if (!string.IsNullOrEmpty(clientSecret.Expiration)) { expiration = DateTime.Parse(clientSecret.Expiration.ToString()); } client.ClientSecrets.Add(new ClientSecret() { Client = client, Value = HashExtensions.Sha256(clientSecret.Value.ToString()), Type = clientSecret.Type.ToString(), Description = clientSecret.Description.ToString(), Expiration = expiration }); } } #endregion ctx.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex); } } }
public void GetMd5Hash() { string hash = HashExtensions.ToMD5("this is a test to hash"); Assert.AreEqual(32, hash.Length); }
public override int GetHashCode() { return(HashExtensions.CombineHashCodes(GetEqualityComponents())); }
public AbpIdentityServerAutoMapperProfile() { #region Client CreateMap <Client, ClientDto>() .ForMember(des => des.IdentityProviderRestrictions, opt => opt.MapFrom(src => src.IdentityProviderRestrictions.Select(x => x.Provider)) ) .ForMember(des => des.PostLogoutRedirectUris, opt => opt.MapFrom(src => src.PostLogoutRedirectUris.Select(x => x.PostLogoutRedirectUri)) ) .ForMember(des => des.RedirectUris, opt => opt.MapFrom(src => src.RedirectUris.Select(x => x.RedirectUri)) ) .ForMember(des => des.AllowedCorsOrigins, opt => opt.MapFrom(src => src.AllowedCorsOrigins.Select(x => x.Origin)) ) .ForMember(des => des.AllowedGrantTypes, opt => opt.MapFrom(src => src.AllowedGrantTypes.Select(x => x.GrantType)) ) .ForMember(des => des.AllowedScopes, opt => opt.MapFrom(src => src.AllowedScopes.Select(x => x.Scope)) ); CreateMap <ClientSecret, ClientSecretDto>() .ReverseMap() .ForPath(des => des.Value, opt => opt.MapFrom(src => HashExtensions.Sha256(src.Value))); CreateMap <ClientProperty, ClientPropertyDto>().ReverseMap(); CreateMap <ClientClaim, ClientClaimDto>().ReverseMap(); CreateMap <ClientUpdateDto, Client>() .Ignore(des => des.IdentityProviderRestrictions) .Ignore(des => des.PostLogoutRedirectUris) .Ignore(des => des.RedirectUris) .Ignore(des => des.AllowedCorsOrigins) .Ignore(des => des.AllowedGrantTypes) .Ignore(des => des.AllowedScopes) .Ignore(des => des.Id) .Ignore(des => des.Properties) .Ignore(des => des.ExtraProperties) .Ignore(des => des.ConcurrencyStamp) .Ignore(des => des.RequireRequestObject) .Ignore(des => des.AllowedIdentityTokenSigningAlgorithms) .IgnoreFullAuditedObjectProperties(); #endregion #region Identity Resource CreateMap <IdentityResource, IdentityResourceDto>() .ForMember(des => des.UserClaims, opt => opt.MapFrom(src => src.UserClaims.Select(x => x.Type))); CreateMap <IdentityResourceCreateUpdateDto, IdentityResource>() .Ignore(des => des.UserClaims) .Ignore(des => des.Id) .Ignore(des => des.Properties) .Ignore(des => des.ExtraProperties) .Ignore(des => des.ConcurrencyStamp) .IgnoreFullAuditedObjectProperties(); #endregion #region Api Resource CreateMap <ApiResource, ApiResourceDto>() .ForMember(des => des.UserClaims, opt => opt.MapFrom(src => src.UserClaims.Select(x => x.Type))) .ForMember(des => des.Scopes, opt => opt.MapFrom(src => src.Scopes.Select(x => x.Scope))); CreateMap <ApiResourceCreateUpdateDto, ApiResource>() .Ignore(des => des.Secrets) .Ignore(des => des.UserClaims) .Ignore(des => des.Scopes) .Ignore(des => des.Id) .Ignore(des => des.Properties) .Ignore(des => des.ExtraProperties) .Ignore(des => des.ConcurrencyStamp) .Ignore(des => des.AllowedAccessTokenSigningAlgorithms) .IgnoreFullAuditedObjectProperties(); #endregion }
/// <summary> /// Gets extended statistics for the current API key. /// </summary> /// <param name="input">Input parameters for the request. See our API documentation at http://defensio.com/api </param> /// <returns>The result of the request.</returns> public DefensioResult GetExtendedStats(Hashtable input) { return(Get(ApiPath("extended-stats"), HashExtensions.ToUrlEncoded(input))); }
/// <summary> /// Submits classification errors (false positives or false negatives). /// </summary> /// <param name="signature">The signature of the document to modify.</param> /// <param name="input">Input parameters for the request. See our API documentation at http://defensio.com/api </param> /// <returns>The result of the request.</returns> /// <remarks> /// Use this option within 30 days of posting a document. /// </remarks> public DefensioResult PutDocument(string signature, Hashtable input) { return(Put(ApiPath("documents", signature), HashExtensions.ToUrlEncoded(input))); }
/// <summary> /// Create and analyze a new document /// </summary> /// <param name="input">Input parameters for the request. See our API documentation at http://defensio.com/api </param> /// <returns>The result of the analysis.</returns> public DefensioResult PostDocument(Hashtable input) { input["client"] = input["client"] ?? _client; return(Post(ApiPath("documents"), HashExtensions.ToUrlEncoded(input))); }
/// <summary> /// Filter a set of values based on a pre-defined dictionary. /// </summary> /// <param name="input">Input parameters for the request. See our API documentation at http://defensio.com/api </param> /// <returns>The filtered input values.</returns> public DefensioResult PostProfanityFilter(Hashtable input) { return(Post(ApiPath("profanity-filter"), HashExtensions.ToUrlEncoded(input))); }
/// <summary> /// Create a password hash /// </summary> /// <param name="password">Password</param> /// <param name="saltkey">Salk key</param> /// <param name="passwordFormat">Password format (hash algorithm)</param> /// <returns>Password hash</returns> public virtual string CreatePasswordHash(string password, string saltkey, string passwordFormat = "SHA512") { return(HashExtensions.CreateHash(Encoding.UTF8.GetBytes(string.Concat(password, saltkey)), passwordFormat)); }
public string HashString(string srcString) { return(HashExtensions.GetMD5Hash(srcString)); }
private string GenerateHashKey(string concatenatedKey) { /* We hash the parameters together to form a unique hash for use as Redis cache Key, * that represents uniquely that combination and we use MD5 hash */ return(HashExtensions.GetMD5HashString(concatenatedKey)); }