public async Task StoreAsync(Model.IdentityResource model) { var entity = model.ToEntity(); try { await StorageContext.SaveBlobWithHashedKeyAsync(entity.Name, JsonConvert.SerializeObject(entity), StorageContext.IdentityResourceBlobContainer); var entities = await GetAllIdentityResourceEntitiesAsync(); entities = entities.Where(e => entity.Name != e.Name).Concat(new Entities.IdentityResource[] { entity }); await UpdateIdentityResourceCacheFileAsync(entities); } catch (AggregateException agg) { ExceptionHelper.LogStorageExceptions(agg, (tblEx) => { _logger.LogWarning("exception updating {apiName} identity resource in table storage: {error}", model.Name, tblEx.Message); }, (blobEx) => { _logger.LogWarning("exception updating {apiName} identity resource in blob storage: {error}", model.Name, blobEx.Message); }); throw; } }
public async Task <IActionResult> AddIdentityResource(IdentityResourceModel identityResource) { if (identityResource == null) { _trackTelemetry.TrackEvent(EventName.AddIdentityResource, EventType.Action, EventStatus.ParameterNotFound); return(BadRequest(_messageConstants.RequestUnsuccessful)); } var user = await _userManager.GetUserAsync(User); if (user == null) { _trackTelemetry.TrackEvent(EventName.AddIdentityResource, EventType.Action, EventStatus.UserNotFound); return(BadRequest(_messageConstants.RequestUnsuccessful)); } _identityResources.TryGetValue(identityResource.Name, out var resource); if (resource == null) { _trackTelemetry.TrackEvent(EventName.AddIdentityResource, EventType.Action, EventStatus.ParameterNotFound); return(BadRequest(_messageConstants.RequestUnsuccessful)); } _configurationDbContext.IdentityResources.Add(resource.ToEntity()); _configurationDbContext.SaveChanges(); _trackTelemetry.TrackEvent(EventName.AddIdentityResource, EventType.Action, EventStatus.Success); return(RedirectToAction(nameof(Index))); }
public async Task <bool> AddIdentityResource(IdentityServer4.Models.IdentityResource resource) { bool Result = false; await Context.IdentityResources.AddAsync(resource.ToEntity()); Result = await Context.SaveChangesAsync() > 0; return(Result); }
private ScopeViewModel CreateScopeViewModel(IdentityServer4.Models.IdentityResource identity, bool check) { return(new ScopeViewModel { Name = identity.Name, DisplayName = identity.DisplayName, Description = identity.Description, Emphasize = identity.Emphasize, Required = identity.Required, Checked = check || identity.Required }); }
public IdentityResource(Guid id, IdentityServer4.Models.IdentityResource resource) : base(id) { Name = resource.Name; DisplayName = resource.DisplayName; Description = resource.Description; Enabled = resource.Enabled; Required = resource.Required; Emphasize = resource.Emphasize; ShowInDiscoveryDocument = resource.ShowInDiscoveryDocument; UserClaims = resource.UserClaims.Select(claimType => new IdentityResourceClaim(id, claimType)).ToList(); Properties = resource.Properties.Select(x => new IdentityResourceProperty(Id, x.Key, x.Value)).ToList(); }
protected virtual async Task AddIdentityResourceIfNotExistsAsync(IdentityServer4.Models.IdentityResource resource) { if (await IdentityResourceRepository.CheckNameExistAsync(resource.Name)) { return; } await IdentityResourceRepository.InsertAsync( new IdentityResource( GuidGenerator.Create(), resource ) ); }
public static IdentityResource ToIdentityResourceViewModel(this IS4.IdentityResource identityResource) { var newResource = new IdentityResource { Enabled = identityResource.Enabled, Name = identityResource.Name, DisplayName = identityResource.DisplayName, Description = identityResource.Description, Required = identityResource.Required, Emphasize = identityResource.Emphasize, ShowInDiscoveryDocument = identityResource.ShowInDiscoveryDocument, UserClaims = new List <string>(identityResource.UserClaims) }; return(newResource); }
public async void ShouldAddAndSaveTheIdentityResourceInTheContext() { var identityResource = new Models.IdentityResource(); var context = A.Fake <IConfigurationDbContext>(); var identityResourceRepository = new IdentityResourceRepository(context); await identityResourceRepository.AddAsync(identityResource); A.CallTo(() => context.SaveChangesAsync()) .MustHaveHappened(); A.CallTo(() => context.IdentityResources.AddAsync( A <Entities.IdentityResource> .Ignored, A <CancellationToken> .Ignored)) .MustHaveHappened(); }
private async Task <IdentityServer4.Models.IdentityResource> CreateIdentityResource(string name, string displayName, bool emphasize, List <string> claimTypes) { var identityResource = new IdentityServer4.Models.IdentityResource(name, displayName, claimTypes); identityResource.Emphasize = emphasize; _configurationContext.IdentityResources.Add(identityResource.ToEntity()); try { await _configurationContext.SaveChangesAsync(); return(identityResource); } catch (Exception) { return(null); } }
public async Task StoreAsync(Model.IdentityResource model) { var entity = model.ToEntity(); try { await StorageContext.SaveBlobAsync(entity.Name, JsonConvert.SerializeObject(entity), StorageContext.IdentityResourceBlobContainer); } catch (AggregateException agg) { ExceptionHelper.LogStorageExceptions(agg, (tblEx) => { _logger.LogWarning("exception updating {apiName} identity resource in table storage: {error}", model.Name, tblEx.Message); }, (blobEx) => { _logger.LogWarning("exception updating {apiName} identity resource in blob storage: {error}", model.Name, blobEx.Message); }); throw; } }
public override async Task CreateStandardResourcesAsync() { var resources = new IdentityResource[] { new IdentityResources.OpenId(), new IdentityResources.Profile { UserClaims = new[] { JwtClaimTypes.Name } } }; foreach (var resource in resources) { foreach (var claimType in resource.UserClaims) { await AddClaimTypeIfNotExistsAsync(claimType); } await AddIdentityResourceIfNotExistsAsync(resource); } }
/// <summary> /// Maps a model to an entity. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> public static IdentityResource ToEntity(this Ids4.IdentityResource model) { return(model == null ? null : Mapper.Map <IdentityResource>(model)); }
/// <summary> /// Maps a model to an entity. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> public static Entities.IdentityResource ToEntity(this Models.IdentityResource model) { return(model == null ? null : Mapper.Map <Entities.IdentityResource>(model)); }
public static IdentityResource ToEntity(this Models.IdentityResource resource) { return(resource == null ? null : Mapper.Map <IdentityResource>(resource)); }
public static IdentityResource ReverseMap(this ids4.IdentityResource source) { return(source == null ? null : Mapper.Map <IdentityResource>(source)); }