feat: add ConfigureAwait(false) to all await calls

pull/2500/head
Javier Campos 5 years ago
parent ad85526379
commit 9422a254ba

@ -28,7 +28,7 @@ namespace Volo.Abp.IdentityServer
public async Task<bool> IsOriginAllowedAsync(string origin) public async Task<bool> IsOriginAllowedAsync(string origin)
{ {
var cacheItem = await Cache.GetOrAddAsync(AllowedCorsOriginsCacheItem.AllOrigins, CreateCacheItemAsync); var cacheItem = await Cache.GetOrAddAsync(AllowedCorsOriginsCacheItem.AllOrigins, CreateCacheItemAsync).ConfigureAwait(false);
var isAllowed = cacheItem.AllowedOrigins.Contains(origin, StringComparer.OrdinalIgnoreCase); var isAllowed = cacheItem.AllowedOrigins.Contains(origin, StringComparer.OrdinalIgnoreCase);
@ -49,7 +49,7 @@ namespace Volo.Abp.IdentityServer
return new AllowedCorsOriginsCacheItem return new AllowedCorsOriginsCacheItem
{ {
AllowedOrigins = (await clientRepository.GetAllDistinctAllowedCorsOriginsAsync()).ToArray() AllowedOrigins = (await clientRepository.GetAllDistinctAllowedCorsOriginsAsync().ConfigureAwait(false)).ToArray()
}; };
} }
} }

@ -21,12 +21,12 @@ namespace Volo.Abp.IdentityServer
public async Task HandleEventAsync(EntityChangedEventData<Client> eventData) public async Task HandleEventAsync(EntityChangedEventData<Client> eventData)
{ {
await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins); await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins).ConfigureAwait(false);
} }
public async Task HandleEventAsync(EntityChangedEventData<ClientCorsOrigin> eventData) public async Task HandleEventAsync(EntityChangedEventData<ClientCorsOrigin> eventData)
{ {
await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins); await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins).ConfigureAwait(false);
} }
} }
} }

@ -28,7 +28,7 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
{ {
using (_currentTenant.Change(context.Subject.FindTenantId())) using (_currentTenant.Change(context.Subject.FindTenantId()))
{ {
await base.GetProfileDataAsync(context); await base.GetProfileDataAsync(context).ConfigureAwait(false);
} }
} }
@ -37,7 +37,7 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
{ {
using (_currentTenant.Change(context.Subject.FindTenantId())) using (_currentTenant.Change(context.Subject.FindTenantId()))
{ {
await base.IsActiveAsync(context); await base.IsActiveAsync(context).ConfigureAwait(false);
} }
} }
} }

@ -43,22 +43,22 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
[UnitOfWork] [UnitOfWork]
public virtual async Task ValidateAsync(ResourceOwnerPasswordValidationContext context) public virtual async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
{ {
await ReplaceEmailToUsernameOfInputIfNeeds(context); await ReplaceEmailToUsernameOfInputIfNeeds(context).ConfigureAwait(false);
var user = await _userManager.FindByNameAsync(context.UserName); var user = await _userManager.FindByNameAsync(context.UserName).ConfigureAwait(false);
if (user != null) if (user != null)
{ {
var result = await _signInManager.CheckPasswordSignInAsync(user, context.Password, true); var result = await _signInManager.CheckPasswordSignInAsync(user, context.Password, true).ConfigureAwait(false);
if (result.Succeeded) if (result.Succeeded)
{ {
var sub = await _userManager.GetUserIdAsync(user); var sub = await _userManager.GetUserIdAsync(user).ConfigureAwait(false);
_logger.LogInformation("Credentials validated for username: {username}", context.UserName); _logger.LogInformation("Credentials validated for username: {username}", context.UserName);
await _events.RaiseAsync(new UserLoginSuccessEvent(context.UserName, sub, context.UserName, interactive: false)); await _events.RaiseAsync(new UserLoginSuccessEvent(context.UserName, sub, context.UserName, interactive: false)).ConfigureAwait(false);
var additionalClaims = new List<Claim>(); var additionalClaims = new List<Claim>();
await AddCustomClaimsAsync(additionalClaims, user, context); await AddCustomClaimsAsync(additionalClaims, user, context).ConfigureAwait(false);
context.Result = new GrantValidationResult( context.Result = new GrantValidationResult(
sub, sub,
@ -71,23 +71,23 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
else if (result.IsLockedOut) else if (result.IsLockedOut)
{ {
_logger.LogInformation("Authentication failed for username: {username}, reason: locked out", context.UserName); _logger.LogInformation("Authentication failed for username: {username}, reason: locked out", context.UserName);
await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "locked out", interactive: false)); await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "locked out", interactive: false)).ConfigureAwait(false);
} }
else if (result.IsNotAllowed) else if (result.IsNotAllowed)
{ {
_logger.LogInformation("Authentication failed for username: {username}, reason: not allowed", context.UserName); _logger.LogInformation("Authentication failed for username: {username}, reason: not allowed", context.UserName);
await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "not allowed", interactive: false)); await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "not allowed", interactive: false)).ConfigureAwait(false);
} }
else else
{ {
_logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", context.UserName); _logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", context.UserName);
await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "invalid credentials", interactive: false)); await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "invalid credentials", interactive: false)).ConfigureAwait(false);
} }
} }
else else
{ {
_logger.LogInformation("No user found matching username: {username}", context.UserName); _logger.LogInformation("No user found matching username: {username}", context.UserName);
await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "invalid username", interactive: false)); await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "invalid username", interactive: false)).ConfigureAwait(false);
} }
context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant); context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant);
@ -100,13 +100,13 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
return; return;
} }
var userByUsername = await _userManager.FindByNameAsync(context.UserName); var userByUsername = await _userManager.FindByNameAsync(context.UserName).ConfigureAwait(false);
if (userByUsername != null) if (userByUsername != null)
{ {
return; return;
} }
var userByEmail = await _userManager.FindByEmailAsync(context.UserName); var userByEmail = await _userManager.FindByEmailAsync(context.UserName).ConfigureAwait(false);
if (userByEmail == null) if (userByEmail == null)
{ {
return; return;

@ -17,7 +17,7 @@ namespace Volo.Abp.IdentityServer.Clients
public virtual async Task<IdentityServer4.Models.Client> FindClientByIdAsync(string clientId) public virtual async Task<IdentityServer4.Models.Client> FindClientByIdAsync(string clientId)
{ {
var client = await _clientRepository.FindByCliendIdAsync(clientId); var client = await _clientRepository.FindByCliendIdAsync(clientId).ConfigureAwait(false);
return _objectMapper.Map<Client, IdentityServer4.Models.Client>(client); return _objectMapper.Map<Client, IdentityServer4.Models.Client>(client);
} }
} }

@ -24,51 +24,51 @@ namespace Volo.Abp.IdentityServer.Grants
public virtual async Task StoreAsync(IdentityServer4.Models.PersistedGrant grant) public virtual async Task StoreAsync(IdentityServer4.Models.PersistedGrant grant)
{ {
var entity = await _persistentGrantRepository.FindByKeyAsync(grant.Key); var entity = await _persistentGrantRepository.FindByKeyAsync(grant.Key).ConfigureAwait(false);
if (entity == null) if (entity == null)
{ {
entity = _objectMapper.Map<IdentityServer4.Models.PersistedGrant, PersistedGrant>(grant); entity = _objectMapper.Map<IdentityServer4.Models.PersistedGrant, PersistedGrant>(grant);
EntityHelper.TrySetId(entity, () => _guidGenerator.Create()); EntityHelper.TrySetId(entity, () => _guidGenerator.Create());
await _persistentGrantRepository.InsertAsync(entity); await _persistentGrantRepository.InsertAsync(entity).ConfigureAwait(false);
} }
else else
{ {
_objectMapper.Map(grant, entity); _objectMapper.Map(grant, entity);
await _persistentGrantRepository.UpdateAsync(entity); await _persistentGrantRepository.UpdateAsync(entity).ConfigureAwait(false);
} }
} }
public virtual async Task<IdentityServer4.Models.PersistedGrant> GetAsync(string key) public virtual async Task<IdentityServer4.Models.PersistedGrant> GetAsync(string key)
{ {
var persistedGrant = await _persistentGrantRepository.FindByKeyAsync(key); var persistedGrant = await _persistentGrantRepository.FindByKeyAsync(key).ConfigureAwait(false);
return _objectMapper.Map<PersistedGrant, IdentityServer4.Models.PersistedGrant>(persistedGrant); return _objectMapper.Map<PersistedGrant, IdentityServer4.Models.PersistedGrant>(persistedGrant);
} }
public virtual async Task<IEnumerable<IdentityServer4.Models.PersistedGrant>> GetAllAsync(string subjectId) public virtual async Task<IEnumerable<IdentityServer4.Models.PersistedGrant>> GetAllAsync(string subjectId)
{ {
var persistedGrants = await _persistentGrantRepository.GetListBySubjectIdAsync(subjectId); var persistedGrants = await _persistentGrantRepository.GetListBySubjectIdAsync(subjectId).ConfigureAwait(false);
return persistedGrants.Select(x => _objectMapper.Map<PersistedGrant, IdentityServer4.Models.PersistedGrant>(x)); return persistedGrants.Select(x => _objectMapper.Map<PersistedGrant, IdentityServer4.Models.PersistedGrant>(x));
} }
public virtual async Task RemoveAsync(string key) public virtual async Task RemoveAsync(string key)
{ {
var persistedGrant = await _persistentGrantRepository.FindByKeyAsync(key); var persistedGrant = await _persistentGrantRepository.FindByKeyAsync(key).ConfigureAwait(false);
if (persistedGrant == null) if (persistedGrant == null)
{ {
return; return;
} }
await _persistentGrantRepository.DeleteAsync(persistedGrant); await _persistentGrantRepository.DeleteAsync(persistedGrant).ConfigureAwait(false);
} }
public virtual async Task RemoveAllAsync(string subjectId, string clientId) public virtual async Task RemoveAllAsync(string subjectId, string clientId)
{ {
await _persistentGrantRepository.DeleteAsync(subjectId, clientId); await _persistentGrantRepository.DeleteAsync(subjectId, clientId).ConfigureAwait(false);
} }
public virtual async Task RemoveAllAsync(string subjectId, string clientId, string type) public virtual async Task RemoveAllAsync(string subjectId, string clientId, string type)
{ {
await _persistentGrantRepository.DeleteAsync(subjectId, clientId, type); await _persistentGrantRepository.DeleteAsync(subjectId, clientId, type).ConfigureAwait(false);
} }
} }
} }

@ -37,16 +37,16 @@ namespace Volo.Abp.IdentityServer.IdentityResources
{ {
foreach (var claimType in resource.UserClaims) foreach (var claimType in resource.UserClaims)
{ {
await AddClaimTypeIfNotExistsAsync(claimType); await AddClaimTypeIfNotExistsAsync(claimType).ConfigureAwait(false);
} }
await AddIdentityResourceIfNotExistsAsync(resource); await AddIdentityResourceIfNotExistsAsync(resource).ConfigureAwait(false);
} }
} }
protected virtual async Task AddIdentityResourceIfNotExistsAsync(IdentityServer4.Models.IdentityResource resource) protected virtual async Task AddIdentityResourceIfNotExistsAsync(IdentityServer4.Models.IdentityResource resource)
{ {
if (await IdentityResourceRepository.CheckNameExistAsync(resource.Name)) if (await IdentityResourceRepository.CheckNameExistAsync(resource.Name).ConfigureAwait(false))
{ {
return; return;
} }
@ -56,12 +56,12 @@ namespace Volo.Abp.IdentityServer.IdentityResources
GuidGenerator.Create(), GuidGenerator.Create(),
resource resource
) )
); ).ConfigureAwait(false);
} }
protected virtual async Task AddClaimTypeIfNotExistsAsync(string claimType) protected virtual async Task AddClaimTypeIfNotExistsAsync(string claimType)
{ {
if (await ClaimTypeRepository.AnyAsync(claimType)) if (await ClaimTypeRepository.AnyAsync(claimType).ConfigureAwait(false))
{ {
return; return;
} }
@ -72,7 +72,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources
claimType, claimType,
isStatic: true isStatic: true
) )
); ).ConfigureAwait(false);
} }
} }
} }

@ -13,14 +13,14 @@ namespace Volo.Abp.IdentityServer.Jwt
{ {
if (ctx.User.Identity?.IsAuthenticated != true) if (ctx.User.Identity?.IsAuthenticated != true)
{ {
var result = await ctx.AuthenticateAsync(schema); var result = await ctx.AuthenticateAsync(schema).ConfigureAwait(false);
if (result.Succeeded && result.Principal != null) if (result.Succeeded && result.Principal != null)
{ {
ctx.User = result.Principal; ctx.User = result.Principal;
} }
} }
await next(); await next().ConfigureAwait(false);
}); });
} }
} }

@ -29,26 +29,26 @@ namespace Volo.Abp.IdentityServer
public virtual async Task<IEnumerable<IdentityServer4.Models.IdentityResource>> FindIdentityResourcesByScopeAsync(IEnumerable<string> scopeNames) public virtual async Task<IEnumerable<IdentityServer4.Models.IdentityResource>> FindIdentityResourcesByScopeAsync(IEnumerable<string> scopeNames)
{ {
var resource = await _identityResourceRepository.GetListByScopesAsync(scopeNames.ToArray(), includeDetails: true); var resource = await _identityResourceRepository.GetListByScopesAsync(scopeNames.ToArray(), includeDetails: true).ConfigureAwait(false);
return _objectMapper.Map<List<IdentityResource>, List<IdentityServer4.Models.IdentityResource>>(resource); return _objectMapper.Map<List<IdentityResource>, List<IdentityServer4.Models.IdentityResource>>(resource);
} }
public virtual async Task<IEnumerable<ApiResource>> FindApiResourcesByScopeAsync(IEnumerable<string> scopeNames) public virtual async Task<IEnumerable<ApiResource>> FindApiResourcesByScopeAsync(IEnumerable<string> scopeNames)
{ {
var resources = await _apiResourceRepository.GetListByScopesAsync(scopeNames.ToArray(), includeDetails: true); var resources = await _apiResourceRepository.GetListByScopesAsync(scopeNames.ToArray(), includeDetails: true).ConfigureAwait(false);
return resources.Select(x => _objectMapper.Map<ApiResources.ApiResource, ApiResource>(x)); return resources.Select(x => _objectMapper.Map<ApiResources.ApiResource, ApiResource>(x));
} }
public virtual async Task<ApiResource> FindApiResourceAsync(string name) public virtual async Task<ApiResource> FindApiResourceAsync(string name)
{ {
var resource = await _apiResourceRepository.FindByNameAsync(name); var resource = await _apiResourceRepository.FindByNameAsync(name).ConfigureAwait(false);
return _objectMapper.Map<ApiResources.ApiResource, ApiResource>(resource); return _objectMapper.Map<ApiResources.ApiResource, ApiResource>(resource);
} }
public virtual async Task<Resources> GetAllResourcesAsync() public virtual async Task<Resources> GetAllResourcesAsync()
{ {
var identityResources = await _identityResourceRepository.GetListAsync(includeDetails: true); var identityResources = await _identityResourceRepository.GetListAsync(includeDetails: true).ConfigureAwait(false);
var apiResources = await _apiResourceRepository.GetListAsync(includeDetails: true); var apiResources = await _apiResourceRepository.GetListAsync(includeDetails: true).ConfigureAwait(false);
return new Resources( return new Resources(
_objectMapper.Map<List<IdentityResource>, IdentityServer4.Models.IdentityResource[]>(identityResources), _objectMapper.Map<List<IdentityResource>, IdentityServer4.Models.IdentityResource[]>(identityResources),

@ -28,7 +28,7 @@ namespace Volo.Abp.IdentityServer.ApiResources
select apiResource; select apiResource;
return await query return await query
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public virtual async Task<List<ApiResource>> GetListByScopesAsync( public virtual async Task<List<ApiResource>> GetListByScopesAsync(
@ -40,7 +40,7 @@ namespace Volo.Abp.IdentityServer.ApiResources
where api.Scopes.Any(x => scopeNames.Contains(x.Name)) where api.Scopes.Any(x => scopeNames.Contains(x.Name))
select api; select api;
return await query.ToListAsync(GetCancellationToken(cancellationToken)); return await query.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public virtual async Task<List<ApiResource>> GetListAsync(string sorting, int skipCount, int maxResultCount, bool includeDetails = false, public virtual async Task<List<ApiResource>> GetListAsync(string sorting, int skipCount, int maxResultCount, bool includeDetails = false,
@ -49,7 +49,7 @@ namespace Volo.Abp.IdentityServer.ApiResources
return await DbSet return await DbSet
.IncludeDetails(includeDetails).OrderBy(sorting ?? "name desc") .IncludeDetails(includeDetails).OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public virtual async Task<List<ApiResource>> GetListAsync( public virtual async Task<List<ApiResource>> GetListAsync(
@ -58,12 +58,12 @@ namespace Volo.Abp.IdentityServer.ApiResources
{ {
return await DbSet return await DbSet
.IncludeDetails(includeDetails) .IncludeDetails(includeDetails)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{ {
return await DbSet.AnyAsync(ar => ar.Id != expectedId && ar.Name == name, cancellationToken: cancellationToken); return await DbSet.AnyAsync(ar => ar.Id != expectedId && ar.Name == name, cancellationToken: cancellationToken).ConfigureAwait(false);
} }
public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default) public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default)
@ -82,7 +82,7 @@ namespace Volo.Abp.IdentityServer.ApiResources
DbContext.Set<ApiScope>().Remove(scope); DbContext.Set<ApiScope>().Remove(scope);
} }
await base.DeleteAsync(id, autoSave, cancellationToken); await base.DeleteAsync(id, autoSave, cancellationToken).ConfigureAwait(false);
} }
public override IQueryable<ApiResource> WithDetails() public override IQueryable<ApiResource> WithDetails()

@ -25,7 +25,7 @@ namespace Volo.Abp.IdentityServer.Clients
{ {
return await DbSet return await DbSet
.IncludeDetails(includeDetails) .IncludeDetails(includeDetails)
.FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public virtual async Task<List<Client>> GetListAsync(string sorting, int skipCount, int maxResultCount, bool includeDetails = false, public virtual async Task<List<Client>> GetListAsync(string sorting, int skipCount, int maxResultCount, bool includeDetails = false,
@ -34,7 +34,7 @@ namespace Volo.Abp.IdentityServer.Clients
return await DbSet return await DbSet
.IncludeDetails(includeDetails).OrderBy(sorting ?? nameof(Client.ClientName) + " desc") .IncludeDetails(includeDetails).OrderBy(sorting ?? nameof(Client.ClientName) + " desc")
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default) public async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default)
@ -42,12 +42,12 @@ namespace Volo.Abp.IdentityServer.Clients
return await DbContext.ClientCorsOrigins return await DbContext.ClientCorsOrigins
.Select(x => x.Origin) .Select(x => x.Origin)
.Distinct() .Distinct()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<bool> CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default) public async Task<bool> CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default)
{ {
return await DbSet.AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, cancellationToken: cancellationToken); return await DbSet.AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, cancellationToken: cancellationToken).ConfigureAwait(false);
} }
public override IQueryable<Client> WithDetails() public override IQueryable<Client> WithDetails()

@ -42,7 +42,7 @@ namespace Volo.Abp.IdentityServer.Grants
await DeleteAsync( await DeleteAsync(
x => x.SubjectId == subjectId && x.ClientId == clientId, x => x.SubjectId == subjectId && x.ClientId == clientId,
cancellationToken: GetCancellationToken(cancellationToken) cancellationToken: GetCancellationToken(cancellationToken)
); ).ConfigureAwait(false);
} }
public async Task DeleteAsync( public async Task DeleteAsync(
@ -54,7 +54,7 @@ namespace Volo.Abp.IdentityServer.Grants
await DeleteAsync( await DeleteAsync(
x => x.SubjectId == subjectId && x.ClientId == clientId && x.Type == type, x => x.SubjectId == subjectId && x.ClientId == clientId && x.Type == type,
cancellationToken: GetCancellationToken(cancellationToken) cancellationToken: GetCancellationToken(cancellationToken)
); ).ConfigureAwait(false);
} }
} }
} }

@ -28,7 +28,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources
where scopeNames.Contains(identityResource.Name) where scopeNames.Contains(identityResource.Name)
select identityResource; select identityResource;
return await query.ToListAsync(GetCancellationToken(cancellationToken)); return await query.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public override IQueryable<IdentityResource> WithDetails() public override IQueryable<IdentityResource> WithDetails()
@ -43,7 +43,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources
.IncludeDetails(includeDetails) .IncludeDetails(includeDetails)
.OrderBy(sorting ?? "name desc") .OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<IdentityResource> FindByNameAsync( public async Task<IdentityResource> FindByNameAsync(
@ -54,12 +54,12 @@ namespace Volo.Abp.IdentityServer.IdentityResources
return await DbSet return await DbSet
.IncludeDetails(includeDetails) .IncludeDetails(includeDetails)
.Where(x => x.Name == name) .Where(x => x.Name == name)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{ {
return await DbSet.AnyAsync(ir => ir.Id != expectedId && ir.Name == name, cancellationToken: cancellationToken); return await DbSet.AnyAsync(ir => ir.Id != expectedId && ir.Name == name, cancellationToken: cancellationToken).ConfigureAwait(false);
} }
} }
} }

@ -21,16 +21,16 @@ namespace Volo.Abp.IdentityServer.MongoDB
public virtual async Task<ApiResource> FindByNameAsync(string name, bool includeDetails = true, CancellationToken cancellationToken = default) public virtual async Task<ApiResource> FindByNameAsync(string name, bool includeDetails = true, CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.Where(ar=>ar.Name == name) .Where(ar => ar.Name == name)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public virtual async Task<List<ApiResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false, public virtual async Task<List<ApiResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.Where(ar=>ar.Scopes.Any(x=> scopeNames.Contains(x.Name))) .Where(ar => ar.Scopes.Any(x => scopeNames.Contains(x.Name)))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public virtual async Task<List<ApiResource>> GetListAsync(string sorting, int skipCount, int maxResultCount, bool includeDetails = false, public virtual async Task<List<ApiResource>> GetListAsync(string sorting, int skipCount, int maxResultCount, bool includeDetails = false,
@ -40,17 +40,17 @@ namespace Volo.Abp.IdentityServer.MongoDB
.OrderBy(sorting ?? nameof(ApiResource.Name)) .OrderBy(sorting ?? nameof(ApiResource.Name))
.As<IMongoQueryable<ApiResource>>() .As<IMongoQueryable<ApiResource>>()
.PageBy<ApiResource, IMongoQueryable<ApiResource>>(skipCount, maxResultCount) .PageBy<ApiResource, IMongoQueryable<ApiResource>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public virtual async Task<long> GetTotalCount() public virtual async Task<long> GetTotalCount()
{ {
return await GetCountAsync(); return await GetCountAsync().ConfigureAwait(false);
} }
public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable().AnyAsync(ar => ar.Id != expectedId && ar.Name == name, cancellationToken: cancellationToken); return await GetMongoQueryable().AnyAsync(ar => ar.Id != expectedId && ar.Name == name, cancellationToken: cancellationToken).ConfigureAwait(false);
} }
} }
} }

@ -26,7 +26,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable().FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken)); return await GetMongoQueryable().FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public virtual async Task<List<Client>> GetListAsync( public virtual async Task<List<Client>> GetListAsync(
@ -40,7 +40,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
.OrderBy(sorting ?? nameof(Client.ClientName)) .OrderBy(sorting ?? nameof(Client.ClientName))
.As<IMongoQueryable<Client>>() .As<IMongoQueryable<Client>>()
.PageBy<Client, IMongoQueryable<Client>>(skipCount, maxResultCount) .PageBy<Client, IMongoQueryable<Client>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync( public async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(
@ -50,17 +50,17 @@ namespace Volo.Abp.IdentityServer.MongoDB
.SelectMany(x => x.AllowedCorsOrigins) .SelectMany(x => x.AllowedCorsOrigins)
.Select(y => y.Origin) .Select(y => y.Origin)
.Distinct() .Distinct()
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<bool> CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default) public async Task<bool> CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable().AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, cancellationToken: cancellationToken); return await GetMongoQueryable().AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, cancellationToken: cancellationToken).ConfigureAwait(false);
} }
public virtual async Task<long> GetTotalCount() public virtual async Task<long> GetTotalCount()
{ {
return await GetCountAsync(); return await GetCountAsync().ConfigureAwait(false);
} }
} }
} }

@ -24,7 +24,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
.OrderBy(sorting ?? nameof(IdentityResource.Name)) .OrderBy(sorting ?? nameof(IdentityResource.Name))
.As<IMongoQueryable<IdentityResource>>() .As<IMongoQueryable<IdentityResource>>()
.PageBy<IdentityResource, IMongoQueryable<IdentityResource>>(skipCount, maxResultCount) .PageBy<IdentityResource, IMongoQueryable<IdentityResource>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<IdentityResource> FindByNameAsync( public async Task<IdentityResource> FindByNameAsync(
@ -34,7 +34,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.Where(x => x.Name == name) .Where(x => x.Name == name)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<List<IdentityResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false, public async Task<List<IdentityResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false,
@ -42,17 +42,17 @@ namespace Volo.Abp.IdentityServer.MongoDB
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.Where(ar => scopeNames.Contains(ar.Name)) .Where(ar => scopeNames.Contains(ar.Name))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public virtual async Task<long> GetTotalCountAsync() public virtual async Task<long> GetTotalCountAsync()
{ {
return await GetCountAsync(); return await GetCountAsync().ConfigureAwait(false);
} }
public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable().AnyAsync(ir => ir.Id != expectedId && ir.Name == name, cancellationToken: cancellationToken); return await GetMongoQueryable().AnyAsync(ir => ir.Id != expectedId && ir.Name == name, cancellationToken: cancellationToken).ConfigureAwait(false);
} }
} }
} }

@ -20,14 +20,14 @@ namespace Volo.Abp.IdentityServer.MongoDB
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.FirstOrDefaultAsync(x => x.Key == key, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(x => x.Key == key, GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<List<PersistedGrant>> GetListBySubjectIdAsync(string subjectId, CancellationToken cancellationToken = default) public async Task<List<PersistedGrant>> GetListBySubjectIdAsync(string subjectId, CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.Where(x => x.SubjectId == subjectId) .Where(x => x.SubjectId == subjectId)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task DeleteAsync(string subjectId, string clientId, CancellationToken cancellationToken = default) public async Task DeleteAsync(string subjectId, string clientId, CancellationToken cancellationToken = default)
@ -35,7 +35,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
await DeleteAsync( await DeleteAsync(
x => x.SubjectId == subjectId && x.ClientId == clientId, x => x.SubjectId == subjectId && x.ClientId == clientId,
cancellationToken: GetCancellationToken(cancellationToken) cancellationToken: GetCancellationToken(cancellationToken)
); ).ConfigureAwait(false);
} }
public async Task DeleteAsync(string subjectId, string clientId, string type, CancellationToken cancellationToken = default) public async Task DeleteAsync(string subjectId, string clientId, string type, CancellationToken cancellationToken = default)
@ -43,7 +43,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
await DeleteAsync( await DeleteAsync(
x => x.SubjectId == subjectId && x.ClientId == clientId && x.Type == type, x => x.SubjectId == subjectId && x.ClientId == clientId && x.Type == type,
cancellationToken: GetCancellationToken(cancellationToken) cancellationToken: GetCancellationToken(cancellationToken)
); ).ConfigureAwait(false);
} }
} }
} }

@ -18,7 +18,7 @@ namespace Volo.Abp.IdentityServer.Clients
[Fact] [Fact]
public async Task FindClientByIdAsync_Should_Return_Null_If_Not_Found() public async Task FindClientByIdAsync_Should_Return_Null_If_Not_Found()
{ {
var client = await _clientStore.FindClientByIdAsync("non-existing-id"); var client = await _clientStore.FindClientByIdAsync("non-existing-id").ConfigureAwait(false);
client.ShouldBeNull(); client.ShouldBeNull();
} }
@ -26,7 +26,7 @@ namespace Volo.Abp.IdentityServer.Clients
public async Task FindClientByIdAsync_Should_Return_The_Client_If_Found() public async Task FindClientByIdAsync_Should_Return_The_Client_If_Found()
{ {
//Act //Act
var client = await _clientStore.FindClientByIdAsync("42"); var client = await _clientStore.FindClientByIdAsync("42").ConfigureAwait(false);
//Assert //Assert
client.ShouldNotBeNull(); client.ShouldNotBeNull();

@ -22,7 +22,7 @@ namespace Volo.Abp.IdentityServer.Clients
public async Task FindApiResourceAsync_Should_Return_Null_If_Not_Found() public async Task FindApiResourceAsync_Should_Return_Null_If_Not_Found()
{ {
//Act //Act
var resource = await _resourceStore.FindApiResourceAsync("non-existing-name"); var resource = await _resourceStore.FindApiResourceAsync("non-existing-name").ConfigureAwait(false);
//Assert //Assert
resource.ShouldBeNull(); resource.ShouldBeNull();
@ -32,7 +32,7 @@ namespace Volo.Abp.IdentityServer.Clients
public async Task FindApiResourceAsync_Should_Return_If_Found() public async Task FindApiResourceAsync_Should_Return_If_Found()
{ {
//Act //Act
var apiResource = await _resourceStore.FindApiResourceAsync("Test-ApiResource-Name-1"); var apiResource = await _resourceStore.FindApiResourceAsync("Test-ApiResource-Name-1").ConfigureAwait(false);
//Assert //Assert
apiResource.ShouldNotBe(null); apiResource.ShouldNotBe(null);
@ -48,7 +48,7 @@ namespace Volo.Abp.IdentityServer.Clients
var apiResources = (await _resourceStore.FindApiResourcesByScopeAsync(new List<string> var apiResources = (await _resourceStore.FindApiResourcesByScopeAsync(new List<string>
{ {
"Test-ApiResource-ApiScope-Name-1" "Test-ApiResource-ApiScope-Name-1"
})).ToList(); }).ConfigureAwait(false)).ToList();
//Assert //Assert
apiResources.ShouldNotBe(null); apiResources.ShouldNotBe(null);
@ -63,7 +63,7 @@ namespace Volo.Abp.IdentityServer.Clients
var identityResourcesByScope = await _resourceStore.FindIdentityResourcesByScopeAsync(new List<string> var identityResourcesByScope = await _resourceStore.FindIdentityResourcesByScopeAsync(new List<string>
{ {
"Test-Identity-Resource-Name-1" "Test-Identity-Resource-Name-1"
}); }).ConfigureAwait(false);
//Assert //Assert
var resourcesByScope = identityResourcesByScope as IdentityResource[] ?? identityResourcesByScope.ToArray(); var resourcesByScope = identityResourcesByScope as IdentityResource[] ?? identityResourcesByScope.ToArray();
@ -77,7 +77,7 @@ namespace Volo.Abp.IdentityServer.Clients
public async Task GetAllResourcesAsync_Should_Return() public async Task GetAllResourcesAsync_Should_Return()
{ {
//Act //Act
var resources = await _resourceStore.GetAllResourcesAsync(); var resources = await _resourceStore.GetAllResourcesAsync().ConfigureAwait(false);
//Assert //Assert
resources.ShouldNotBe(null); resources.ShouldNotBe(null);

@ -21,7 +21,7 @@ namespace Volo.Abp.IdentityServer.Clients
[Fact] [Fact]
public async Task FindClientByIdAsync_Should_Return_Null_If_Not_Found() public async Task FindClientByIdAsync_Should_Return_Null_If_Not_Found()
{ {
var persistentGrant = await _persistedGrantStore.GetAsync("not-existing-id"); var persistentGrant = await _persistedGrantStore.GetAsync("not-existing-id").ConfigureAwait(false);
persistentGrant.ShouldBeNull(); persistentGrant.ShouldBeNull();
} }
@ -29,7 +29,7 @@ namespace Volo.Abp.IdentityServer.Clients
public async Task FindPersistentGrantByIdAsync_Should_Return_The_PersistentGrant_If_Found() public async Task FindPersistentGrantByIdAsync_Should_Return_The_PersistentGrant_If_Found()
{ {
//Act //Act
var client = await _persistedGrantStore.GetAsync("38"); var client = await _persistedGrantStore.GetAsync("38").ConfigureAwait(false);
//Assert //Assert
client.ShouldNotBeNull(); client.ShouldNotBeNull();
@ -52,10 +52,10 @@ namespace Volo.Abp.IdentityServer.Clients
Data = "TestData-39", Data = "TestData-39",
Expiration = new DateTime(2018, 1, 6, 21, 22, 23), Expiration = new DateTime(2018, 1, 6, 21, 22, 23),
CreationTime = new DateTime(2018, 1, 5, 19, 20, 21) CreationTime = new DateTime(2018, 1, 5, 19, 20, 21)
}); }).ConfigureAwait(false);
//Assert //Assert
var persistedGrant = await _persistedGrantStore.GetAsync("39"); var persistedGrant = await _persistedGrantStore.GetAsync("39").ConfigureAwait(false);
persistedGrant.Key.ShouldBe("39"); persistedGrant.Key.ShouldBe("39");
persistedGrant.ClientId.ShouldBe("TestClientId-39"); persistedGrant.ClientId.ShouldBe("TestClientId-39");
persistedGrant.Type.ShouldBe("TestType-39"); persistedGrant.Type.ShouldBe("TestType-39");
@ -92,10 +92,10 @@ namespace Volo.Abp.IdentityServer.Clients
Data = "TestData-PersistedGrantKey1", Data = "TestData-PersistedGrantKey1",
Expiration = new DateTime(2018, 1, 6, 21, 22, 23), Expiration = new DateTime(2018, 1, 6, 21, 22, 23),
CreationTime = new DateTime(2018, 1, 5, 19, 20, 21) CreationTime = new DateTime(2018, 1, 5, 19, 20, 21)
}); }).ConfigureAwait(false);
//Assert //Assert
var persistedGrant = await _persistedGrantStore.GetAsync("PersistedGrantKey1"); var persistedGrant = await _persistedGrantStore.GetAsync("PersistedGrantKey1").ConfigureAwait(false);
persistedGrant.Key.ShouldBe("PersistedGrantKey1"); persistedGrant.Key.ShouldBe("PersistedGrantKey1");
persistedGrant.ClientId.ShouldBe("TestClientId-PersistedGrantKey1"); persistedGrant.ClientId.ShouldBe("TestClientId-PersistedGrantKey1");
persistedGrant.Type.ShouldBe("TestType-PersistedGrantKey1"); persistedGrant.Type.ShouldBe("TestType-PersistedGrantKey1");
@ -122,7 +122,7 @@ namespace Volo.Abp.IdentityServer.Clients
public async Task GetAllAsync_Should_Get_All_PersistedGrants_For_A_Given_SubjectId() public async Task GetAllAsync_Should_Get_All_PersistedGrants_For_A_Given_SubjectId()
{ {
//Act //Act
var persistentGrants = await _persistedGrantStore.GetAllAsync("TestSubject"); var persistentGrants = await _persistedGrantStore.GetAllAsync("TestSubject").ConfigureAwait(false);
//Assert //Assert
var persistedGrants = persistentGrants as PersistedGrant[] ?? persistentGrants.ToArray(); var persistedGrants = persistentGrants as PersistedGrant[] ?? persistentGrants.ToArray();
@ -142,13 +142,13 @@ namespace Volo.Abp.IdentityServer.Clients
Type = "Type", Type = "Type",
ClientId = "ClientId", ClientId = "ClientId",
Data = "" Data = ""
}); }).ConfigureAwait(false);
//Act //Act
await _persistedGrantStore.RemoveAsync("#1P3R"); await _persistedGrantStore.RemoveAsync("#1P3R").ConfigureAwait(false);
//Assert //Assert
var persistedGrant = await _persistedGrantStore.GetAsync("#1P3R"); var persistedGrant = await _persistedGrantStore.GetAsync("#1P3R").ConfigureAwait(false);
persistedGrant.ShouldBe(null); persistedGrant.ShouldBe(null);
} }
@ -156,16 +156,16 @@ namespace Volo.Abp.IdentityServer.Clients
public async Task RemoveAllAsync_Should_RemoveAll_PeristedGrants_For_A_Given_Subject_And_ClientId() public async Task RemoveAllAsync_Should_RemoveAll_PeristedGrants_For_A_Given_Subject_And_ClientId()
{ {
//Arrange //Arrange
var persistedGrantsWithTestSubjectX = await _persistedGrantStore.GetAllAsync("TestSubject-X"); var persistedGrantsWithTestSubjectX = await _persistedGrantStore.GetAllAsync("TestSubject-X").ConfigureAwait(false);
var persistedGrantsWithTestSubjectXBeforeLength = persistedGrantsWithTestSubjectX.ToArray().Length; var persistedGrantsWithTestSubjectXBeforeLength = persistedGrantsWithTestSubjectX.ToArray().Length;
//Act //Act
await _persistedGrantStore.RemoveAllAsync("TestSubject-X", "TestClientId-X"); await _persistedGrantStore.RemoveAllAsync("TestSubject-X", "TestClientId-X").ConfigureAwait(false);
//Assert //Assert
persistedGrantsWithTestSubjectXBeforeLength.ShouldBe(2); persistedGrantsWithTestSubjectXBeforeLength.ShouldBe(2);
var persistedGrants = (await _persistedGrantStore.GetAllAsync("TestClientId-37")).ToArray(); var persistedGrants = (await _persistedGrantStore.GetAllAsync("TestClientId-37").ConfigureAwait(false)).ToArray();
persistedGrants.ShouldNotBe(null); persistedGrants.ShouldNotBe(null);
persistedGrants.Length.ShouldBe(0); persistedGrants.Length.ShouldBe(0);
} }

@ -23,27 +23,27 @@ namespace Volo.Abp.IdentityServer
[Fact] [Fact]
public async Task IsOriginAllowedAsync() public async Task IsOriginAllowedAsync()
{ {
(await _corsPolicyService.IsOriginAllowedAsync("https://client1-origin.com")).ShouldBeTrue(); (await _corsPolicyService.IsOriginAllowedAsync("https://client1-origin.com").ConfigureAwait(false)).ShouldBeTrue();
(await _corsPolicyService.IsOriginAllowedAsync("https://unknown-origin.com")).ShouldBeFalse(); (await _corsPolicyService.IsOriginAllowedAsync("https://unknown-origin.com").ConfigureAwait(false)).ShouldBeFalse();
} }
[Fact] [Fact]
public async Task IsOriginAllowedAsync_Should_Invalidate_Cache_On_Update() public async Task IsOriginAllowedAsync_Should_Invalidate_Cache_On_Update()
{ {
//It does not exists before //It does not exists before
(await _corsPolicyService.IsOriginAllowedAsync("https://new-origin.com")).ShouldBeFalse(); (await _corsPolicyService.IsOriginAllowedAsync("https://new-origin.com").ConfigureAwait(false)).ShouldBeFalse();
using (var uow = _unitOfWorkManager.Begin()) using (var uow = _unitOfWorkManager.Begin())
{ {
var client1 = await _clientRepository.FindByCliendIdAsync("ClientId1"); var client1 = await _clientRepository.FindByCliendIdAsync("ClientId1").ConfigureAwait(false);
client1.AddCorsOrigin("https://new-origin.com"); client1.AddCorsOrigin("https://new-origin.com");
await _clientRepository.UpdateAsync(client1); await _clientRepository.UpdateAsync(client1).ConfigureAwait(false);
await uow.CompleteAsync(); await uow.CompleteAsync().ConfigureAwait(false);
} }
//It does exists now //It does exists now
(await _corsPolicyService.IsOriginAllowedAsync("https://new-origin.com")).ShouldBeTrue(); (await _corsPolicyService.IsOriginAllowedAsync("https://new-origin.com").ConfigureAwait(false)).ShouldBeTrue();
} }
} }
} }

@ -39,10 +39,10 @@ namespace Volo.Abp.IdentityServer
public async Task BuildAsync() public async Task BuildAsync()
{ {
await AddClients(); await AddClients().ConfigureAwait(false);
await AddPersistentGrants(); await AddPersistentGrants().ConfigureAwait(false);
await AddApiResources(); await AddApiResources().ConfigureAwait(false);
await AddIdentityResources(); await AddIdentityResources().ConfigureAwait(false);
} }
private async Task AddClients() private async Task AddClients()
@ -56,7 +56,7 @@ namespace Volo.Abp.IdentityServer
client42.AddScope("api1"); client42.AddScope("api1");
await _clientRepository.InsertAsync(client42); await _clientRepository.InsertAsync(client42).ConfigureAwait(false);
} }
private async Task AddPersistentGrants() private async Task AddPersistentGrants()
@ -68,7 +68,7 @@ namespace Volo.Abp.IdentityServer
Type = "TestType-38", Type = "TestType-38",
SubjectId = "TestSubject", SubjectId = "TestSubject",
Data = "TestData-38" Data = "TestData-38"
}); }).ConfigureAwait(false);
await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create())
{ {
@ -77,7 +77,7 @@ namespace Volo.Abp.IdentityServer
Type = "TestType-37", Type = "TestType-37",
SubjectId = "TestSubject", SubjectId = "TestSubject",
Data = "TestData-37" Data = "TestData-37"
}); }).ConfigureAwait(false);
await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create())
{ {
@ -86,7 +86,7 @@ namespace Volo.Abp.IdentityServer
Type = "TestType-36", Type = "TestType-36",
SubjectId = "TestSubject-X", SubjectId = "TestSubject-X",
Data = "TestData-36" Data = "TestData-36"
}); }).ConfigureAwait(false);
await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create())
{ {
@ -95,7 +95,7 @@ namespace Volo.Abp.IdentityServer
Type = "TestType-35", Type = "TestType-35",
SubjectId = "TestSubject-X", SubjectId = "TestSubject-X",
Data = "TestData-35" Data = "TestData-35"
}); }).ConfigureAwait(false);
} }
private async Task AddApiResources() private async Task AddApiResources()
@ -111,7 +111,7 @@ namespace Volo.Abp.IdentityServer
apiResource.AddScope("Test-ApiResource-ApiScope-Name-1", "Test-ApiResource-ApiScope-DisplayName-1"); apiResource.AddScope("Test-ApiResource-ApiScope-Name-1", "Test-ApiResource-ApiScope-DisplayName-1");
apiResource.AddUserClaim("Test-ApiResource-Claim-Type-1"); apiResource.AddUserClaim("Test-ApiResource-Claim-Type-1");
await _apiResourceRepository.InsertAsync(apiResource); await _apiResourceRepository.InsertAsync(apiResource).ConfigureAwait(false);
} }
private async Task AddIdentityResources() private async Task AddIdentityResources()
@ -126,7 +126,7 @@ namespace Volo.Abp.IdentityServer
identityResource.AddUserClaim("Test-Identity-Resource-1-IdentityClaim-Type-1"); identityResource.AddUserClaim("Test-Identity-Resource-1-IdentityClaim-Type-1");
await _identityResourceRepository.InsertAsync(identityResource); await _identityResourceRepository.InsertAsync(identityResource).ConfigureAwait(false);
} }
} }
} }

@ -41,11 +41,11 @@ namespace Volo.Abp.IdentityServer
public async Task BuildAsync() public async Task BuildAsync()
{ {
await AddPersistedGrants(); await AddPersistedGrants().ConfigureAwait(false);
await AddIdentityResources(); await AddIdentityResources().ConfigureAwait(false);
await AddApiResources(); await AddApiResources().ConfigureAwait(false);
await AddClients(); await AddClients().ConfigureAwait(false);
await AddClaimTypes(); await AddClaimTypes().ConfigureAwait(false);
} }
private async Task AddPersistedGrants() private async Task AddPersistedGrants()
@ -57,7 +57,7 @@ namespace Volo.Abp.IdentityServer
ClientId = "PersistedGrantClientId1", ClientId = "PersistedGrantClientId1",
Type = "PersistedGrantType1", Type = "PersistedGrantType1",
Data = "" Data = ""
}); }).ConfigureAwait(false);
await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create())
{ {
@ -66,7 +66,7 @@ namespace Volo.Abp.IdentityServer
ClientId = "c1", ClientId = "c1",
Type = "c1type", Type = "c1type",
Data = "" Data = ""
}); }).ConfigureAwait(false);
await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create())
{ {
@ -75,7 +75,7 @@ namespace Volo.Abp.IdentityServer
ClientId = "c1", ClientId = "c1",
Type = "c1type", Type = "c1type",
Data = "" Data = ""
}); }).ConfigureAwait(false);
} }
private async Task AddIdentityResources() private async Task AddIdentityResources()
@ -88,9 +88,9 @@ namespace Volo.Abp.IdentityServer
identityResource.AddUserClaim(nameof(ApiResourceClaim.Type)); identityResource.AddUserClaim(nameof(ApiResourceClaim.Type));
await _identityResourceRepository.InsertAsync(identityResource); await _identityResourceRepository.InsertAsync(identityResource).ConfigureAwait(false);
await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource2")); await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource2")).ConfigureAwait(false);
await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource3")); await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource3")).ConfigureAwait(false);
} }
private async Task AddApiResources() private async Task AddApiResources()
@ -103,9 +103,9 @@ namespace Volo.Abp.IdentityServer
apiResource.AddUserClaim(nameof(ApiResourceClaim.Type)); apiResource.AddUserClaim(nameof(ApiResourceClaim.Type));
apiResource.AddSecret(nameof(ApiSecret.Value)); apiResource.AddSecret(nameof(ApiSecret.Value));
await _apiResourceRepository.InsertAsync(apiResource); await _apiResourceRepository.InsertAsync(apiResource).ConfigureAwait(false);
await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource2")); await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource2")).ConfigureAwait(false);
await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource3")); await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource3")).ConfigureAwait(false);
} }
private async Task AddClients() private async Task AddClients()
@ -130,17 +130,17 @@ namespace Volo.Abp.IdentityServer
client.AddScope(nameof(ClientScope.Scope)); client.AddScope(nameof(ClientScope.Scope));
client.AddSecret(nameof(ClientSecret.Value)); client.AddSecret(nameof(ClientSecret.Value));
await _clientRepository.InsertAsync(client); await _clientRepository.InsertAsync(client).ConfigureAwait(false);
await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId2")); await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId2")).ConfigureAwait(false);
await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId3")); await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId3")).ConfigureAwait(false);
} }
private async Task AddClaimTypes() private async Task AddClaimTypes()
{ {
var ageClaim = new IdentityClaimType(Guid.NewGuid(), "Age", false, false, null, null, null, var ageClaim = new IdentityClaimType(Guid.NewGuid(), "Age", false, false, null, null, null,
IdentityClaimValueType.Int); IdentityClaimValueType.Int);
await _identityClaimTypeRepository.InsertAsync(ageClaim); await _identityClaimTypeRepository.InsertAsync(ageClaim).ConfigureAwait(false);
} }
} }
} }

@ -20,13 +20,13 @@ namespace Volo.Abp.IdentityServer
[Fact] [Fact]
public async Task FindByNormalizedNameAsync() public async Task FindByNormalizedNameAsync()
{ {
(await apiResourceRepository.FindByNameAsync("NewApiResource2")).ShouldNotBeNull(); (await apiResourceRepository.FindByNameAsync("NewApiResource2").ConfigureAwait(false)).ShouldNotBeNull();
} }
[Fact] [Fact]
public async Task GetListByScopesAsync() public async Task GetListByScopesAsync()
{ {
(await apiResourceRepository.GetListByScopesAsync(new []{ "NewApiResource2", "NewApiResource3"})).Count.ShouldBe(2); (await apiResourceRepository.GetListByScopesAsync(new[] { "NewApiResource2", "NewApiResource3" }).ConfigureAwait(false)).Count.ShouldBe(2);
} }
} }
} }

@ -21,13 +21,13 @@ namespace Volo.Abp.IdentityServer
[Fact] [Fact]
public async Task FindByCliendIdAsync() public async Task FindByCliendIdAsync()
{ {
(await clientRepository.FindByCliendIdAsync("ClientId2")).ShouldNotBeNull(); (await clientRepository.FindByCliendIdAsync("ClientId2").ConfigureAwait(false)).ShouldNotBeNull();
} }
[Fact] [Fact]
public async Task GetAllDistinctAllowedCorsOriginsAsync() public async Task GetAllDistinctAllowedCorsOriginsAsync()
{ {
var origins = await clientRepository.GetAllDistinctAllowedCorsOriginsAsync(); var origins = await clientRepository.GetAllDistinctAllowedCorsOriginsAsync().ConfigureAwait(false);
origins.Any().ShouldBeTrue(); origins.Any().ShouldBeTrue();
} }
} }

@ -23,7 +23,7 @@ namespace Volo.Abp.IdentityServer
[Fact] [Fact]
public async Task GetListByScopesAsync() public async Task GetListByScopesAsync()
{ {
(await identityResourceRepository.GetListByScopesAsync(new []{"", "NewIdentityResource2" })).Count.ShouldBe(1); (await identityResourceRepository.GetListByScopesAsync(new[] { "", "NewIdentityResource2" }).ConfigureAwait(false)).Count.ShouldBe(1);
} }
} }
} }

@ -22,13 +22,13 @@ namespace Volo.Abp.IdentityServer
[Fact] [Fact]
public async Task FindByKeyAsync() public async Task FindByKeyAsync()
{ {
(await _persistentGrantRepository.FindByKeyAsync("PersistedGrantKey1")).ShouldNotBeNull(); (await _persistentGrantRepository.FindByKeyAsync("PersistedGrantKey1").ConfigureAwait(false)).ShouldNotBeNull();
} }
[Fact] [Fact]
public async Task GetListBySubjectIdAsync() public async Task GetListBySubjectIdAsync()
{ {
var persistedGrants = await _persistentGrantRepository.GetListBySubjectIdAsync("PersistedGrantSubjectId1"); var persistedGrants = await _persistentGrantRepository.GetListBySubjectIdAsync("PersistedGrantSubjectId1").ConfigureAwait(false);
persistedGrants.ShouldNotBeEmpty(); persistedGrants.ShouldNotBeEmpty();
persistedGrants.ShouldContain(x => x.Key == "PersistedGrantKey1"); persistedGrants.ShouldContain(x => x.Key == "PersistedGrantKey1");
} }
@ -36,9 +36,9 @@ namespace Volo.Abp.IdentityServer
[Fact] [Fact]
public async Task DeleteBySubjectIdAndClientId() public async Task DeleteBySubjectIdAndClientId()
{ {
await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantClientId1"); await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantClientId1").ConfigureAwait(false);
var persistedGrants = await _persistentGrantRepository.GetListAsync(); var persistedGrants = await _persistentGrantRepository.GetListAsync().ConfigureAwait(false);
persistedGrants.ShouldNotBeEmpty(); persistedGrants.ShouldNotBeEmpty();
persistedGrants.ShouldNotContain(x => persistedGrants.ShouldNotContain(x =>
x.Key == "PersistedGrantKey1" && x.SubjectId == "PersistedGrantSubjectId1" && x.Key == "PersistedGrantKey1" && x.SubjectId == "PersistedGrantSubjectId1" &&
@ -49,9 +49,9 @@ namespace Volo.Abp.IdentityServer
public async Task DeleteBySubjectIdAndClientIdAndType() public async Task DeleteBySubjectIdAndClientIdAndType()
{ {
await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantClientId1", await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantClientId1",
"PersistedGrantClientId1"); "PersistedGrantClientId1").ConfigureAwait(false);
var persistedGrants = await _persistentGrantRepository.GetListAsync(); var persistedGrants = await _persistentGrantRepository.GetListAsync().ConfigureAwait(false);
persistedGrants.ShouldNotBeEmpty(); persistedGrants.ShouldNotBeEmpty();
persistedGrants.ShouldNotContain(x => persistedGrants.ShouldNotContain(x =>
x.Key == "PersistedGrantKey1" && x.SubjectId == "PersistedGrantSubjectId1" && x.Key == "PersistedGrantKey1" && x.SubjectId == "PersistedGrantSubjectId1" &&

Loading…
Cancel
Save