This commit is contained in:
2026-11-26 19:36:49 +03:30
parent 4e114aa85a
commit bdc8791822
8 changed files with 752 additions and 921 deletions
+139 -139
View File
@@ -13,162 +13,162 @@ namespace xIdentityService.Providers
{
public partial class XAuthorizationProvider
{
//
#region Scope ...
public async Task<XQueryResult<XScopeDefinitionDto>> QueryScopesAsync(
XQuery query,
CancellationToken cancellationToken = default
)
{
//
if (query.IsNull())
{
XException.InvalidArgs.Throw();
}
// //
// #region Scope ...
// public async Task<XQueryResult<XScopeDefinitionDto>> QueryScopesAsync(
// XQuery query,
// CancellationToken cancellationToken = default
// )
// {
// //
// if (query.IsNull())
// {
// XException.InvalidArgs.Throw();
// }
//
var result = await scopes.QueryAsync(
query: query,
cancellationToken: cancellationToken
);
// //
// var result = await scopes.QueryAsync(
// query: query,
// cancellationToken: cancellationToken
// );
//
return result;
}
// //
// return result;
// }
public async Task<XScopeDefinitionDto> GetScopeAsync(
string name,
CancellationToken cancellationToken = default
)
{
//
var result = await FindScopeOrThrowAsync(name, cancellationToken);
// public async Task<XScopeDefinitionDto> GetScopeAsync(
// string name,
// CancellationToken cancellationToken = default
// )
// {
// //
// var result = await FindScopeOrThrowAsync(name, cancellationToken);
//
return result;
}
// //
// return result;
// }
public async Task<XScopeDefinitionDto> AddScopeAsync(
XScopeDefinitionDto item,
XUserClaimsInfoDto userInfo,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
if (item.IsNull() || item.Name.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
// public async Task<XScopeDefinitionDto> AddScopeAsync(
// XScopeDefinitionDto item,
// XUserClaimsInfoDto userInfo,
// CancellationToken cancellationToken = default
// )
// {
// //
// // Validate ...
// if (item.IsNull() || item.Name.IsNullOrEmpty())
// {
// XException.InvalidArgs.Throw();
// }
//
// Duplicate check ...
var normalized = item.Name.ToNormalString();
var exists = await scopes.FindOneAsync(
cancellationToken: cancellationToken,
predicate: s => s.Name.ToLower() == normalized
);
if (!exists.IsNull())
{
XException.Duplicate.Throw();
}
// //
// // Duplicate check ...
// var normalized = item.Name.ToNormalString();
// var exists = await scopes.FindOneAsync(
// cancellationToken: cancellationToken,
// predicate: s => s.Name.ToLower() == normalized
// );
// if (!exists.IsNull())
// {
// XException.Duplicate.Throw();
// }
//
// Persist ...
item.IsSystem = false;
var result = await scopes.AddAsync(
item: item,
userInfo: userInfo,
cancellationToken: cancellationToken
);
// //
// // Persist ...
// item.IsSystem = false;
// var result = await scopes.AddAsync(
// item: item,
// userInfo: userInfo,
// cancellationToken: cancellationToken
// );
//
// Sync to IdentityServer (ConfigurationDbContext) ...
var entity = scopes.AsQueryable()
.FirstOrDefault(s => s.Name.ToLower() == normalized);
if (!entity.IsNull())
{
//
await scopeSync
.UpsertAsync(entity, cancellationToken);
}
// //
// // Sync to IdentityServer (ConfigurationDbContext) ...
// var entity = scopes.AsQueryable()
// .FirstOrDefault(s => s.Name.ToLower() == normalized);
// if (!entity.IsNull())
// {
// //
// await scopeSync
// .UpsertAsync(entity, cancellationToken);
// }
//
await InvalidateAsync();
return result;
}
// //
// await InvalidateAsync();
// return result;
// }
public async Task<XScopeDefinitionDto> UpdateScopeAsync(
string name,
XScopeDefinitionDto item,
XUserClaimsInfoDto userInfo,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
if (name.IsNullOrEmpty() || item.IsNull())
{
XException.InvalidArgs.Throw();
}
// public async Task<XScopeDefinitionDto> UpdateScopeAsync(
// string name,
// XScopeDefinitionDto item,
// XUserClaimsInfoDto userInfo,
// CancellationToken cancellationToken = default
// )
// {
// //
// // Validate ...
// if (name.IsNullOrEmpty() || item.IsNull())
// {
// XException.InvalidArgs.Throw();
// }
//
var existing = await FindScopeOrThrowAsync(name, cancellationToken);
if (existing.IsSystem)
{
XException.NotAllowed.Throw();
}
// //
// var existing = await FindScopeOrThrowAsync(name, cancellationToken);
// if (existing.IsSystem)
// {
// XException.NotAllowed.Throw();
// }
//
var updated = await scopes.UpdateAsync(
id: existing.Id,
item: item,
userInfo: userInfo,
cancellationToken: cancellationToken
);
// //
// var updated = await scopes.UpdateAsync(
// id: existing.Id,
// item: item,
// userInfo: userInfo,
// cancellationToken: cancellationToken
// );
//
// Sync to IdentityServer ...
var entity = scopes.AsQueryable()
.FirstOrDefault(s => s.Name.ToLower() == name.ToNormalString());
if (!entity.IsNull())
{
await scopeSync.UpsertAsync(entity, cancellationToken);
}
// //
// // Sync to IdentityServer ...
// var entity = scopes.AsQueryable()
// .FirstOrDefault(s => s.Name.ToLower() == name.ToNormalString());
// if (!entity.IsNull())
// {
// await scopeSync.UpsertAsync(entity, cancellationToken);
// }
//
await InvalidateAsync();
return updated;
}
// //
// await InvalidateAsync();
// return updated;
// }
public async Task<bool> RemoveScopeAsync(
string name,
XUserClaimsInfoDto userInfo,
CancellationToken cancellationToken = default
)
{
//
var entity = await FindScopeOrThrowAsync(name, cancellationToken);
if (entity.IsSystem)
{
XException.NotAllowed.Throw();
}
// public async Task<bool> RemoveScopeAsync(
// string name,
// XUserClaimsInfoDto userInfo,
// CancellationToken cancellationToken = default
// )
// {
// //
// var entity = await FindScopeOrThrowAsync(name, cancellationToken);
// if (entity.IsSystem)
// {
// XException.NotAllowed.Throw();
// }
//
await scopes.RemoveAsync(
id: entity.Id,
userInfo: userInfo,
cancellationToken: cancellationToken
);
// //
// await scopes.RemoveAsync(
// id: entity.Id,
// userInfo: userInfo,
// cancellationToken: cancellationToken
// );
//
// Remove from IdentityServer ...
await scopeSync.RemoveAsync(name, cancellationToken);
// //
// // Remove from IdentityServer ...
// await scopeSync.RemoveAsync(name, cancellationToken);
//
await InvalidateAsync();
return true;
}
#endregion
// //
// await InvalidateAsync();
// return true;
// }
// #endregion
}
}