Browse Source

chore(identity-server): some detailed improvements.

pull/10142/head
PM Extra 5 years ago
parent
commit
3149f770ea
  1. 4
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs
  2. 4
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScope.cs
  3. 6
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowStore.cs
  4. 18
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrant.cs
  5. 7
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs
  6. 30
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs
  7. 13
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiScopes/ApiScopeRepository.cs
  8. 2
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs
  9. 6
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs
  10. 3
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistentGrantRepository.cs
  11. 14
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs
  12. 5
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs
  13. 15
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs
  14. 7
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs
  15. 2
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs

4
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs

@ -35,12 +35,10 @@ namespace Volo.Abp.IdentityServer.ApiResources
}
public ApiResource(Guid id, [NotNull] string name, string displayName = null, string description = null)
public ApiResource(Guid id, [NotNull] string name, string displayName = null, string description = null) : base(id)
{
Check.NotNull(name, nameof(name));
Id = id;
Name = name;
DisplayName = displayName;

4
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScope.cs

@ -40,11 +40,11 @@ namespace Volo.Abp.IdentityServer.ApiScopes
bool required = false,
bool emphasize = false,
bool showInDiscoveryDocument = true,
bool enabled = true)
bool enabled = true
) : base(id)
{
Check.NotNull(name, nameof(name));
Id = id;
Name = name;
DisplayName = displayName ?? name;
Description = description;

6
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowStore.cs

@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks;
using IdentityModel;
using IdentityServer4.Models;
@ -38,7 +38,7 @@ namespace Volo.Abp.IdentityServer.Devices
DeviceCode = deviceCode,
UserCode = userCode,
ClientId = data.ClientId,
SubjectId = data.Subject?.FindFirst(JwtClaimTypes.Subject).Value,
SubjectId = data.Subject?.FindFirst(JwtClaimTypes.Subject)?.Value,
CreationTime = data.CreationTime,
Expiration = data.CreationTime.AddSeconds(data.Lifetime),
Data = Serialize(data)
@ -93,7 +93,7 @@ namespace Volo.Abp.IdentityServer.Devices
throw new InvalidOperationException($"Could not update device code by the given userCode: {userCode}");
}
deviceCodes.SubjectId = data.Subject?.FindFirst(JwtClaimTypes.Subject).Value;
deviceCodes.SubjectId = data.Subject?.FindFirst(JwtClaimTypes.Subject)?.Value;
deviceCodes.Data = Serialize(data);
await DeviceFlowCodesRepository

18
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrant.cs

@ -5,6 +5,14 @@ namespace Volo.Abp.IdentityServer.Grants
{
public class PersistedGrant : AggregateRoot<Guid>
{
protected PersistedGrant()
{
}
public PersistedGrant(Guid id) : base(id)
{
}
public virtual string Key { get; set; }
public virtual string Type { get; set; }
@ -24,15 +32,5 @@ namespace Volo.Abp.IdentityServer.Grants
public virtual DateTime? ConsumedTime { get; set; }
public virtual string Data { get; set; }
protected PersistedGrant()
{
}
public PersistedGrant(Guid id)
{
Id = id;
}
}
}

7
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs

@ -39,11 +39,11 @@ namespace Volo.Abp.IdentityServer.IdentityResources
bool enabled = true,
bool required = false,
bool emphasize = false,
bool showInDiscoveryDocument = true)
bool showInDiscoveryDocument = true
) : base(id)
{
Check.NotNull(name, nameof(name));
Id = id;
Name = name;
DisplayName = displayName;
Description = description;
@ -56,9 +56,8 @@ namespace Volo.Abp.IdentityServer.IdentityResources
Properties = new List<IdentityResourceProperty>();
}
public IdentityResource(Guid id, IdentityServer4.Models.IdentityResource resource)
public IdentityResource(Guid id, IdentityServer4.Models.IdentityResource resource) : base(id)
{
Id = id;
Name = resource.Name;
DisplayName = resource.DisplayName;
Description = resource.Description;

30
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs

@ -20,23 +20,20 @@ namespace Volo.Abp.IdentityServer.ApiResources
public async Task<ApiResource> FindByNameAsync(string apiResourceName, bool includeDetails = true, CancellationToken cancellationToken = default)
{
var query = from apiResource in (await GetDbSetAsync()).IncludeDetails(includeDetails)
where apiResource.Name == apiResourceName
orderby apiResource.Id
select apiResource;
return await query.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.OrderBy(apiResource => apiResource.Id)
.FirstOrDefaultAsync(apiResource => apiResource.Name == apiResourceName, GetCancellationToken(cancellationToken));
}
public async Task<List<ApiResource>> FindByNameAsync(string[] apiResourceNames, bool includeDetails = true,
CancellationToken cancellationToken = default)
{
var query = from apiResource in (await GetDbSetAsync()).IncludeDetails(includeDetails)
where apiResourceNames.Contains(apiResource.Name)
orderby apiResource.Name
select apiResource;
return await query.ToListAsync(GetCancellationToken(cancellationToken));
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(apiResource => apiResourceNames.Contains(apiResource.Name))
.OrderBy(apiResource => apiResource.Name)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<ApiResource>> GetListByScopesAsync(
@ -44,11 +41,10 @@ namespace Volo.Abp.IdentityServer.ApiResources
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var query = from api in (await GetDbSetAsync()).IncludeDetails(includeDetails)
where api.Scopes.Any(x => scopeNames.Contains(x.Scope))
select api;
return await query.ToListAsync(GetCancellationToken(cancellationToken));
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(api => api.Scopes.Any(x => scopeNames.Contains(x.Scope)))
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<ApiResource>> GetListAsync(

13
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiScopes/ApiScopeRepository.cs

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
@ -29,12 +29,11 @@ namespace Volo.Abp.IdentityServer.ApiScopes
public async Task<List<ApiScope>> GetListByNameAsync(string[] scopeNames, bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var query = from scope in (await GetDbSetAsync()).IncludeDetails(includeDetails)
where scopeNames.Contains(scope.Name)
orderby scope.Id
select scope;
return await query.ToListAsync(GetCancellationToken(cancellationToken));
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(scope => scopeNames.Contains(scope.Name))
.OrderBy(scope => scope.Id)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<ApiScope>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default)

2
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs

@ -58,7 +58,7 @@ namespace Volo.Abp.IdentityServer.Clients
public virtual async Task<bool> CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync()).AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, cancellationToken: cancellationToken);
return await (await GetDbSetAsync()).AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, GetCancellationToken(cancellationToken));
}
public async override Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default)

6
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs

@ -24,9 +24,8 @@ namespace Volo.Abp.IdentityServer.Devices
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(d => d.UserCode == userCode)
.OrderBy(d => d.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
.FirstOrDefaultAsync(d => d.UserCode == userCode, GetCancellationToken(cancellationToken));
}
public virtual async Task<DeviceFlowCodes> FindByDeviceCodeAsync(
@ -34,9 +33,8 @@ namespace Volo.Abp.IdentityServer.Devices
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(d => d.DeviceCode == deviceCode)
.OrderBy(d => d.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
.FirstOrDefaultAsync(d => d.DeviceCode == deviceCode, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<DeviceFlowCodes>> GetListByExpirationAsync(DateTime maxExpirationDate, int maxResultCount,

3
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistentGrantRepository.cs

@ -30,9 +30,8 @@ namespace Volo.Abp.IdentityServer.Grants
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(x => x.Key == key)
.OrderBy(x => x.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
.FirstOrDefaultAsync(x => x.Key == key, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<PersistedGrant>> GetListBySubjectIdAsync(

14
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs

@ -24,11 +24,10 @@ namespace Volo.Abp.IdentityServer.IdentityResources
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var query = from identityResource in (await GetDbSetAsync()).IncludeDetails(includeDetails)
where scopeNames.Contains(identityResource.Name)
select identityResource;
return await query.ToListAsync(GetCancellationToken(cancellationToken));
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(identityResource => scopeNames.Contains(identityResource.Name))
.ToListAsync(GetCancellationToken(cancellationToken));
}
[Obsolete("Use WithDetailsAsync method.")]
@ -72,14 +71,13 @@ namespace Volo.Abp.IdentityServer.IdentityResources
{
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(x => x.Name == name)
.OrderBy(x => x.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
.FirstOrDefaultAsync(x => x.Name == name, GetCancellationToken(cancellationToken));
}
public virtual async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync()).AnyAsync(ir => ir.Id != expectedId && ir.Name == name, cancellationToken: cancellationToken);
return await (await GetDbSetAsync()).AnyAsync(ir => ir.Id != expectedId && ir.Name == name, GetCancellationToken(cancellationToken));
}
}
}

5
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@ -21,9 +21,8 @@ namespace Volo.Abp.IdentityServer.MongoDB
public async Task<ApiResource> FindByNameAsync(string apiResourceName, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
.Where(ar => ar.Name == apiResourceName)
.OrderBy(ar => ar.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
.FirstOrDefaultAsync(ar => ar.Name == apiResourceName, GetCancellationToken(cancellationToken));
}
public async Task<List<ApiResource>> FindByNameAsync(string[] apiResourceNames, bool includeDetails = true,

15
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@ -23,20 +23,17 @@ namespace Volo.Abp.IdentityServer.MongoDB
public async Task<ApiScope> FindByNameAsync(string scopeName, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
.Where(x => x.Name == scopeName)
.OrderBy(x => x.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
.FirstOrDefaultAsync(x => x.Name == scopeName, GetCancellationToken(cancellationToken));
}
public async Task<List<ApiScope>> GetListByNameAsync(string[] scopeNames, bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var query = from scope in (await GetMongoQueryableAsync(cancellationToken))
where scopeNames.Contains(scope.Name)
orderby scope.Id
select scope;
return await query.ToListAsync(GetCancellationToken(cancellationToken));
return await (await GetMongoQueryableAsync(cancellationToken))
.Where(scope => scopeNames.Contains(scope.Name))
.OrderBy(scope => scope.Id)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<ApiScope>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false,

7
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@ -27,9 +27,8 @@ namespace Volo.Abp.IdentityServer.MongoDB
CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
.Where(x => x.ClientId == clientId)
.OrderBy(x => x.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
.FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<Client>> GetListAsync(
@ -69,7 +68,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
public virtual async Task<bool> CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
.AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, cancellationToken: cancellationToken);
.AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, GetCancellationToken(cancellationToken));
}
}
}

2
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs

@ -62,7 +62,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
public virtual async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
.AnyAsync(ir => ir.Id != expectedId && ir.Name == name, cancellationToken: cancellationToken);
.AnyAsync(ir => ir.Id != expectedId && ir.Name == name, GetCancellationToken(cancellationToken));
}
}
}

Loading…
Cancel
Save