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)
{
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);
@ -49,7 +49,7 @@ namespace Volo.Abp.IdentityServer
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)
{
await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins);
await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins).ConfigureAwait(false);
}
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()))
{
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()))
{
await base.IsActiveAsync(context);
await base.IsActiveAsync(context).ConfigureAwait(false);
}
}
}

@ -43,22 +43,22 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
[UnitOfWork]
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)
{
var result = await _signInManager.CheckPasswordSignInAsync(user, context.Password, true);
var result = await _signInManager.CheckPasswordSignInAsync(user, context.Password, true).ConfigureAwait(false);
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);
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>();
await AddCustomClaimsAsync(additionalClaims, user, context);
await AddCustomClaimsAsync(additionalClaims, user, context).ConfigureAwait(false);
context.Result = new GrantValidationResult(
sub,
@ -71,23 +71,23 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
else if (result.IsLockedOut)
{
_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)
{
_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
{
_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
{
_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);
@ -100,13 +100,13 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
return;
}
var userByUsername = await _userManager.FindByNameAsync(context.UserName);
var userByUsername = await _userManager.FindByNameAsync(context.UserName).ConfigureAwait(false);
if (userByUsername != null)
{
return;
}
var userByEmail = await _userManager.FindByEmailAsync(context.UserName);
var userByEmail = await _userManager.FindByEmailAsync(context.UserName).ConfigureAwait(false);
if (userByEmail == null)
{
return;

@ -17,7 +17,7 @@ namespace Volo.Abp.IdentityServer.Clients
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);
}
}

@ -24,51 +24,51 @@ namespace Volo.Abp.IdentityServer.Grants
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)
{
entity = _objectMapper.Map<IdentityServer4.Models.PersistedGrant, PersistedGrant>(grant);
EntityHelper.TrySetId(entity, () => _guidGenerator.Create());
await _persistentGrantRepository.InsertAsync(entity);
await _persistentGrantRepository.InsertAsync(entity).ConfigureAwait(false);
}
else
{
_objectMapper.Map(grant, entity);
await _persistentGrantRepository.UpdateAsync(entity);
await _persistentGrantRepository.UpdateAsync(entity).ConfigureAwait(false);
}
}
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);
}
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));
}
public virtual async Task RemoveAsync(string key)
{
var persistedGrant = await _persistentGrantRepository.FindByKeyAsync(key);
var persistedGrant = await _persistentGrantRepository.FindByKeyAsync(key).ConfigureAwait(false);
if (persistedGrant == null)
{
return;
}
await _persistentGrantRepository.DeleteAsync(persistedGrant);
await _persistentGrantRepository.DeleteAsync(persistedGrant).ConfigureAwait(false);
}
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)
{
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)
{
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)
{
if (await IdentityResourceRepository.CheckNameExistAsync(resource.Name))
if (await IdentityResourceRepository.CheckNameExistAsync(resource.Name).ConfigureAwait(false))
{
return;
}
@ -56,12 +56,12 @@ namespace Volo.Abp.IdentityServer.IdentityResources
GuidGenerator.Create(),
resource
)
);
).ConfigureAwait(false);
}
protected virtual async Task AddClaimTypeIfNotExistsAsync(string claimType)
{
if (await ClaimTypeRepository.AnyAsync(claimType))
if (await ClaimTypeRepository.AnyAsync(claimType).ConfigureAwait(false))
{
return;
}
@ -72,7 +72,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources
claimType,
isStatic: true
)
);
).ConfigureAwait(false);
}
}
}

@ -13,14 +13,14 @@ namespace Volo.Abp.IdentityServer.Jwt
{
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)
{
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)
{
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);
}
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));
}
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);
}
public virtual async Task<Resources> GetAllResourcesAsync()
{
var identityResources = await _identityResourceRepository.GetListAsync(includeDetails: true);
var apiResources = await _apiResourceRepository.GetListAsync(includeDetails: true);
var identityResources = await _identityResourceRepository.GetListAsync(includeDetails: true).ConfigureAwait(false);
var apiResources = await _apiResourceRepository.GetListAsync(includeDetails: true).ConfigureAwait(false);
return new Resources(
_objectMapper.Map<List<IdentityResource>, IdentityServer4.Models.IdentityResource[]>(identityResources),

@ -28,7 +28,7 @@ namespace Volo.Abp.IdentityServer.ApiResources
select apiResource;
return await query
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
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))
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,
@ -49,7 +49,7 @@ namespace Volo.Abp.IdentityServer.ApiResources
return await DbSet
.IncludeDetails(includeDetails).OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public virtual async Task<List<ApiResource>> GetListAsync(
@ -58,12 +58,12 @@ namespace Volo.Abp.IdentityServer.ApiResources
{
return await DbSet
.IncludeDetails(includeDetails)
.ToListAsync(GetCancellationToken(cancellationToken));
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
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)
@ -82,7 +82,7 @@ namespace Volo.Abp.IdentityServer.ApiResources
DbContext.Set<ApiScope>().Remove(scope);
}
await base.DeleteAsync(id, autoSave, cancellationToken);
await base.DeleteAsync(id, autoSave, cancellationToken).ConfigureAwait(false);
}
public override IQueryable<ApiResource> WithDetails()

@ -25,7 +25,7 @@ namespace Volo.Abp.IdentityServer.Clients
{
return await DbSet
.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,
@ -34,7 +34,7 @@ namespace Volo.Abp.IdentityServer.Clients
return await DbSet
.IncludeDetails(includeDetails).OrderBy(sorting ?? nameof(Client.ClientName) + " desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default)
@ -42,12 +42,12 @@ namespace Volo.Abp.IdentityServer.Clients
return await DbContext.ClientCorsOrigins
.Select(x => x.Origin)
.Distinct()
.ToListAsync(GetCancellationToken(cancellationToken));
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
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()

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

@ -28,7 +28,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources
where scopeNames.Contains(identityResource.Name)
select identityResource;
return await query.ToListAsync(GetCancellationToken(cancellationToken));
return await query.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public override IQueryable<IdentityResource> WithDetails()
@ -43,7 +43,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources
.IncludeDetails(includeDetails)
.OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public async Task<IdentityResource> FindByNameAsync(
@ -54,12 +54,12 @@ namespace Volo.Abp.IdentityServer.IdentityResources
return await DbSet
.IncludeDetails(includeDetails)
.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)
{
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)
{
return await GetMongoQueryable()
.Where(ar=>ar.Name == name)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
.Where(ar => ar.Name == name)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public virtual async Task<List<ApiResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.Where(ar=>ar.Scopes.Any(x=> scopeNames.Contains(x.Name)))
.ToListAsync(GetCancellationToken(cancellationToken));
.Where(ar => ar.Scopes.Any(x => scopeNames.Contains(x.Name)))
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(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))
.As<IMongoQueryable<ApiResource>>()
.PageBy<ApiResource, IMongoQueryable<ApiResource>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
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)
{
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,
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(
@ -40,7 +40,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
.OrderBy(sorting ?? nameof(Client.ClientName))
.As<IMongoQueryable<Client>>()
.PageBy<Client, IMongoQueryable<Client>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(
@ -50,17 +50,17 @@ namespace Volo.Abp.IdentityServer.MongoDB
.SelectMany(x => x.AllowedCorsOrigins)
.Select(y => y.Origin)
.Distinct()
.ToListAsync(GetCancellationToken(cancellationToken));
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
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()
{
return await GetCountAsync();
return await GetCountAsync().ConfigureAwait(false);
}
}
}

@ -24,7 +24,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
.OrderBy(sorting ?? nameof(IdentityResource.Name))
.As<IMongoQueryable<IdentityResource>>()
.PageBy<IdentityResource, IMongoQueryable<IdentityResource>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public async Task<IdentityResource> FindByNameAsync(
@ -34,7 +34,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
{
return await GetMongoQueryable()
.Where(x => x.Name == name)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public async Task<List<IdentityResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false,
@ -42,17 +42,17 @@ namespace Volo.Abp.IdentityServer.MongoDB
{
return await GetMongoQueryable()
.Where(ar => scopeNames.Contains(ar.Name))
.ToListAsync(GetCancellationToken(cancellationToken));
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
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)
{
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()
.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)
{
return await GetMongoQueryable()
.Where(x => x.SubjectId == subjectId)
.ToListAsync(GetCancellationToken(cancellationToken));
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public async Task DeleteAsync(string subjectId, string clientId, CancellationToken cancellationToken = default)
@ -35,7 +35,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
await DeleteAsync(
x => x.SubjectId == subjectId && x.ClientId == clientId,
cancellationToken: GetCancellationToken(cancellationToken)
);
).ConfigureAwait(false);
}
public async Task DeleteAsync(string subjectId, string clientId, string type, CancellationToken cancellationToken = default)
@ -43,7 +43,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
await DeleteAsync(
x => x.SubjectId == subjectId && x.ClientId == clientId && x.Type == type,
cancellationToken: GetCancellationToken(cancellationToken)
);
).ConfigureAwait(false);
}
}
}

@ -18,7 +18,7 @@ namespace Volo.Abp.IdentityServer.Clients
[Fact]
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();
}
@ -26,7 +26,7 @@ namespace Volo.Abp.IdentityServer.Clients
public async Task FindClientByIdAsync_Should_Return_The_Client_If_Found()
{
//Act
var client = await _clientStore.FindClientByIdAsync("42");
var client = await _clientStore.FindClientByIdAsync("42").ConfigureAwait(false);
//Assert
client.ShouldNotBeNull();

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

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

@ -23,27 +23,27 @@ namespace Volo.Abp.IdentityServer
[Fact]
public async Task IsOriginAllowedAsync()
{
(await _corsPolicyService.IsOriginAllowedAsync("https://client1-origin.com")).ShouldBeTrue();
(await _corsPolicyService.IsOriginAllowedAsync("https://unknown-origin.com")).ShouldBeFalse();
(await _corsPolicyService.IsOriginAllowedAsync("https://client1-origin.com").ConfigureAwait(false)).ShouldBeTrue();
(await _corsPolicyService.IsOriginAllowedAsync("https://unknown-origin.com").ConfigureAwait(false)).ShouldBeFalse();
}
[Fact]
public async Task IsOriginAllowedAsync_Should_Invalidate_Cache_On_Update()
{
//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())
{
var client1 = await _clientRepository.FindByCliendIdAsync("ClientId1");
var client1 = await _clientRepository.FindByCliendIdAsync("ClientId1").ConfigureAwait(false);
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
(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()
{
await AddClients();
await AddPersistentGrants();
await AddApiResources();
await AddIdentityResources();
await AddClients().ConfigureAwait(false);
await AddPersistentGrants().ConfigureAwait(false);
await AddApiResources().ConfigureAwait(false);
await AddIdentityResources().ConfigureAwait(false);
}
private async Task AddClients()
@ -56,7 +56,7 @@ namespace Volo.Abp.IdentityServer
client42.AddScope("api1");
await _clientRepository.InsertAsync(client42);
await _clientRepository.InsertAsync(client42).ConfigureAwait(false);
}
private async Task AddPersistentGrants()
@ -68,7 +68,7 @@ namespace Volo.Abp.IdentityServer
Type = "TestType-38",
SubjectId = "TestSubject",
Data = "TestData-38"
});
}).ConfigureAwait(false);
await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create())
{
@ -77,7 +77,7 @@ namespace Volo.Abp.IdentityServer
Type = "TestType-37",
SubjectId = "TestSubject",
Data = "TestData-37"
});
}).ConfigureAwait(false);
await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create())
{
@ -86,7 +86,7 @@ namespace Volo.Abp.IdentityServer
Type = "TestType-36",
SubjectId = "TestSubject-X",
Data = "TestData-36"
});
}).ConfigureAwait(false);
await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create())
{
@ -95,7 +95,7 @@ namespace Volo.Abp.IdentityServer
Type = "TestType-35",
SubjectId = "TestSubject-X",
Data = "TestData-35"
});
}).ConfigureAwait(false);
}
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.AddUserClaim("Test-ApiResource-Claim-Type-1");
await _apiResourceRepository.InsertAsync(apiResource);
await _apiResourceRepository.InsertAsync(apiResource).ConfigureAwait(false);
}
private async Task AddIdentityResources()
@ -126,7 +126,7 @@ namespace Volo.Abp.IdentityServer
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()
{
await AddPersistedGrants();
await AddIdentityResources();
await AddApiResources();
await AddClients();
await AddClaimTypes();
await AddPersistedGrants().ConfigureAwait(false);
await AddIdentityResources().ConfigureAwait(false);
await AddApiResources().ConfigureAwait(false);
await AddClients().ConfigureAwait(false);
await AddClaimTypes().ConfigureAwait(false);
}
private async Task AddPersistedGrants()
@ -57,7 +57,7 @@ namespace Volo.Abp.IdentityServer
ClientId = "PersistedGrantClientId1",
Type = "PersistedGrantType1",
Data = ""
});
}).ConfigureAwait(false);
await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create())
{
@ -66,7 +66,7 @@ namespace Volo.Abp.IdentityServer
ClientId = "c1",
Type = "c1type",
Data = ""
});
}).ConfigureAwait(false);
await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create())
{
@ -75,7 +75,7 @@ namespace Volo.Abp.IdentityServer
ClientId = "c1",
Type = "c1type",
Data = ""
});
}).ConfigureAwait(false);
}
private async Task AddIdentityResources()
@ -88,9 +88,9 @@ namespace Volo.Abp.IdentityServer
identityResource.AddUserClaim(nameof(ApiResourceClaim.Type));
await _identityResourceRepository.InsertAsync(identityResource);
await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource2"));
await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource3"));
await _identityResourceRepository.InsertAsync(identityResource).ConfigureAwait(false);
await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource2")).ConfigureAwait(false);
await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource3")).ConfigureAwait(false);
}
private async Task AddApiResources()
@ -103,9 +103,9 @@ namespace Volo.Abp.IdentityServer
apiResource.AddUserClaim(nameof(ApiResourceClaim.Type));
apiResource.AddSecret(nameof(ApiSecret.Value));
await _apiResourceRepository.InsertAsync(apiResource);
await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource2"));
await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource3"));
await _apiResourceRepository.InsertAsync(apiResource).ConfigureAwait(false);
await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource2")).ConfigureAwait(false);
await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource3")).ConfigureAwait(false);
}
private async Task AddClients()
@ -130,17 +130,17 @@ namespace Volo.Abp.IdentityServer
client.AddScope(nameof(ClientScope.Scope));
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(), "ClientId3"));
await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId2")).ConfigureAwait(false);
await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId3")).ConfigureAwait(false);
}
private async Task AddClaimTypes()
{
var ageClaim = new IdentityClaimType(Guid.NewGuid(), "Age", false, false, null, null, null,
IdentityClaimValueType.Int);
await _identityClaimTypeRepository.InsertAsync(ageClaim);
await _identityClaimTypeRepository.InsertAsync(ageClaim).ConfigureAwait(false);
}
}
}

@ -20,13 +20,13 @@ namespace Volo.Abp.IdentityServer
[Fact]
public async Task FindByNormalizedNameAsync()
{
(await apiResourceRepository.FindByNameAsync("NewApiResource2")).ShouldNotBeNull();
(await apiResourceRepository.FindByNameAsync("NewApiResource2").ConfigureAwait(false)).ShouldNotBeNull();
}
[Fact]
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]
public async Task FindByCliendIdAsync()
{
(await clientRepository.FindByCliendIdAsync("ClientId2")).ShouldNotBeNull();
(await clientRepository.FindByCliendIdAsync("ClientId2").ConfigureAwait(false)).ShouldNotBeNull();
}
[Fact]
public async Task GetAllDistinctAllowedCorsOriginsAsync()
{
var origins = await clientRepository.GetAllDistinctAllowedCorsOriginsAsync();
var origins = await clientRepository.GetAllDistinctAllowedCorsOriginsAsync().ConfigureAwait(false);
origins.Any().ShouldBeTrue();
}
}

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

Loading…
Cancel
Save