This repository has been archived by the owner on Aug 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add IClientStore、IResourceStore * Code optimization * feat(oidc):oidc * feat(oidc):oidc * feat(oidc):oidc * feat(oidc):oidc * feat(oidc):oidc * feat(oidc):oidc * feat:update client * feat:update cache * feat(oidc):oidc * feat(oidc):oidc * feat(oidc):oidc * refactor:formatting code * feat(oidc):oidc * feat(oidc):remove AddAllAsync,add ResetAsync * feat(oidc):sln * refactor:refactor code * refactor(code):refactor code * refactor:refactor code * refactor:refactor code * fix:ReUse change to Reuse * refactor(code):refactor code Co-authored-by: Mayue <mayue@lonsid.cn>
- Loading branch information
1 parent
3389384
commit 8ed77e9
Showing
73 changed files
with
2,419 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Authentication/Masa.BuildingBlocks.Authentication.Oidc.Cache/Caches/IApiResourceCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.Authentication.Oidc.Cache.Caches; | ||
|
||
public interface IApiResourceCache | ||
{ | ||
Task<List<ApiResourceModel>> GetListAsync(IEnumerable<string> names); | ||
|
||
Task<List<ApiResourceModel>> GetListAsync(); | ||
|
||
Task SetAsync(ApiResource apiResource); | ||
|
||
Task SetRangeAsync(IEnumerable<ApiResource> apiResources); | ||
|
||
Task RemoveAsync(ApiResource apiResource); | ||
|
||
Task ResetAsync(IEnumerable<ApiResource> identityResources); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Authentication/Masa.BuildingBlocks.Authentication.Oidc.Cache/Caches/IApiScopeCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.Authentication.Oidc.Cache.Caches; | ||
|
||
public interface IApiScopeCache | ||
{ | ||
Task<List<ApiScopeModel>> GetListAsync(IEnumerable<string> names); | ||
|
||
Task<List<ApiScopeModel>> GetListAsync(); | ||
|
||
Task SetAsync(ApiScope apiScope); | ||
|
||
Task SetRangeAsync(IEnumerable<ApiScope> apiScopes); | ||
|
||
Task RemoveAsync(ApiScope apiScope); | ||
|
||
Task ResetAsync(IEnumerable<ApiScope> identityResources); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Authentication/Masa.BuildingBlocks.Authentication.Oidc.Cache/Caches/IClientCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.Authentication.Oidc.Cache.Caches; | ||
|
||
public interface IClientCache | ||
{ | ||
Task<ClientModel?> GetAsync(string clientId); | ||
|
||
Task SetAsync(Client client); | ||
|
||
Task SetRangeAsync(IEnumerable<Client> clients); | ||
|
||
Task RemoveAsync(Client client); | ||
} |
19 changes: 19 additions & 0 deletions
19
...entication/Masa.BuildingBlocks.Authentication.Oidc.Cache/Caches/IIdentityResourceCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.Authentication.Oidc.Cache.Caches; | ||
|
||
public interface IIdentityResourceCache | ||
{ | ||
Task<List<IdentityResourceModel>> GetListAsync(IEnumerable<string> names); | ||
|
||
Task<List<IdentityResourceModel>> GetListAsync(); | ||
|
||
Task SetAsync(IdentityResource identityResource); | ||
|
||
Task SetRangeAsync(IEnumerable<IdentityResource> identityResources); | ||
|
||
Task RemoveAsync(IdentityResource identityResource); | ||
|
||
Task ResetAsync(IEnumerable<IdentityResource> identityResources); | ||
} |
14 changes: 14 additions & 0 deletions
14
...dingBlocks.Authentication.Oidc.Cache/Masa.BuildingBlocks.Authentication.Oidc.Cache.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Masa.BuildingBlocks.Authentication.Oidc.Domain\Masa.BuildingBlocks.Authentication.Oidc.Domain.csproj" /> | ||
<ProjectReference Include="..\Masa.BuildingBlocks.Authentication.Oidc.Models\Masa.BuildingBlocks.Authentication.Oidc.Models.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
5 changes: 5 additions & 0 deletions
5
src/Authentication/Masa.BuildingBlocks.Authentication.Oidc.Cache/_Imports.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
global using Masa.BuildingBlocks.Authentication.Oidc.Domain.Entities; | ||
global using Masa.BuildingBlocks.Authentication.Oidc.Models.Models; |
37 changes: 37 additions & 0 deletions
37
...uthentication/Masa.BuildingBlocks.Authentication.Oidc.Domain/Constants/GrantTypeConsts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.Authentication.Oidc.Domain.Constants; | ||
|
||
public class GrantTypeConsts | ||
{ | ||
public static ICollection<string> Implicit => | ||
new[] { GrantTypes.IMPLICIT }; | ||
|
||
public static ICollection<string> ImplicitAndClientCredentials => | ||
new[] { GrantTypes.IMPLICIT, GrantTypes.CLIENT_CREDENTIALS }; | ||
|
||
public static ICollection<string> Code => | ||
new[] { GrantTypes.AUTHORIZATION_CODE }; | ||
|
||
public static ICollection<string> CodeAndClientCredentials => | ||
new[] { GrantTypes.AUTHORIZATION_CODE, GrantTypes.CLIENT_CREDENTIALS }; | ||
|
||
public static ICollection<string> Hybrid => | ||
new[] { GrantTypes.HYBRID }; | ||
|
||
public static ICollection<string> HybridAndClientCredentials => | ||
new[] { GrantTypes.HYBRID, GrantTypes.CLIENT_CREDENTIALS }; | ||
|
||
public static ICollection<string> ClientCredentials => | ||
new[] { GrantTypes.CLIENT_CREDENTIALS }; | ||
|
||
public static ICollection<string> ResourceOwnerPassword => | ||
new[] { GrantTypes.RESOURCE_OWNER_PASSWORD }; | ||
|
||
public static ICollection<string> ResourceOwnerPasswordAndClientCredentials => | ||
new[] { GrantTypes.RESOURCE_OWNER_PASSWORD, GrantTypes.CLIENT_CREDENTIALS }; | ||
|
||
public static ICollection<string> DeviceFlow => | ||
new[] { GrantTypes.DEVICE_FLOW }; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Authentication/Masa.BuildingBlocks.Authentication.Oidc.Domain/Constants/GrantTypes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.Authentication.Oidc.Domain.Constants; | ||
|
||
public static class GrantTypes | ||
{ | ||
public const string IMPLICIT = "implicit"; | ||
|
||
public const string HYBRID = "hybrid"; | ||
|
||
public const string AUTHORIZATION_CODE = "authorization_code"; | ||
|
||
public const string CLIENT_CREDENTIALS = "client_credentials"; | ||
|
||
public const string RESOURCE_OWNER_PASSWORD = "password"; | ||
|
||
public const string DEVICE_FLOW = "urn:ietf:params:oauth:grant-type:device_code"; | ||
} |
11 changes: 11 additions & 0 deletions
11
...thentication/Masa.BuildingBlocks.Authentication.Oidc.Domain/Entities/Abstract/Property.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.Authentication.Oidc.Domain.Entities.Abstract; | ||
|
||
public abstract class Property : Entity<Guid> | ||
{ | ||
public string Key { get; protected set; } = ""; | ||
|
||
public string Value { get; protected set; } = ""; | ||
} |
15 changes: 15 additions & 0 deletions
15
...Authentication/Masa.BuildingBlocks.Authentication.Oidc.Domain/Entities/Abstract/Secret.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.Authentication.Oidc.Domain.Entities.Abstract; | ||
|
||
public abstract class Secret : FullEntity<int, Guid> | ||
{ | ||
public string Description { get; protected set; } = string.Empty; | ||
|
||
public string Value { get; protected set; } = string.Empty; | ||
|
||
public DateTime? Expiration { get; protected set; } | ||
|
||
public string Type { get; protected set; } = "SharedSecret"; | ||
} |
78 changes: 78 additions & 0 deletions
78
src/Authentication/Masa.BuildingBlocks.Authentication.Oidc.Domain/Entities/ApiResource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.Authentication.Oidc.Domain.Entities; | ||
|
||
public class ApiResource : FullAggregateRoot<int, Guid> | ||
{ | ||
private List<ApiResourceSecret> _secrets = new(); | ||
private List<ApiResourceScope> _apiScopes = new(); | ||
private List<ApiResourceClaim> _userClaims = new(); | ||
private List<ApiResourceProperty> _properties = new(); | ||
|
||
public bool Enabled { get; private set; } | ||
|
||
public string Name { get; private set; } = ""; | ||
|
||
public string DisplayName { get; private set; } = ""; | ||
|
||
public string Description { get; private set; } = ""; | ||
|
||
public string AllowedAccessTokenSigningAlgorithms { get; private set; } = ""; | ||
|
||
public bool ShowInDiscoveryDocument { get; private set; } = true; | ||
|
||
public DateTime? LastAccessed { get; private set; } | ||
|
||
public bool NonEditable { get; private set; } | ||
|
||
public IReadOnlyCollection<ApiResourceSecret> Secrets => _secrets; | ||
|
||
public IReadOnlyCollection<ApiResourceScope> ApiScopes => _apiScopes; | ||
|
||
public IReadOnlyCollection<ApiResourceClaim> UserClaims => _userClaims; | ||
|
||
public IReadOnlyCollection<ApiResourceProperty> Properties => _properties; | ||
|
||
public ApiResource(string name, string displayName, string description, string allowedAccessTokenSigningAlgorithms, bool showInDiscoveryDocument, DateTime? lastAccessed, bool nonEditable, bool enabled) | ||
{ | ||
Enabled = enabled; | ||
Name = name; | ||
DisplayName = displayName; | ||
Description = description; | ||
AllowedAccessTokenSigningAlgorithms = allowedAccessTokenSigningAlgorithms; | ||
ShowInDiscoveryDocument = showInDiscoveryDocument; | ||
LastAccessed = lastAccessed; | ||
NonEditable = nonEditable; | ||
} | ||
|
||
public void Update(string displayName, string description, string allowedAccessTokenSigningAlgorithms, bool showInDiscoveryDocument, DateTime? lastAccessed, bool nonEditable, bool enabled) | ||
{ | ||
Enabled = enabled; | ||
DisplayName = displayName; | ||
Description = description; | ||
AllowedAccessTokenSigningAlgorithms = allowedAccessTokenSigningAlgorithms; | ||
ShowInDiscoveryDocument = showInDiscoveryDocument; | ||
LastAccessed = lastAccessed; | ||
NonEditable = nonEditable; | ||
} | ||
|
||
public void BindUserClaims(List<int> userClaims) | ||
{ | ||
_userClaims.Clear(); | ||
_userClaims.AddRange(userClaims.Select(id => new ApiResourceClaim(id))); | ||
} | ||
|
||
public void BindProperties(Dictionary<string, string> properties) | ||
{ | ||
_properties.Clear(); | ||
_properties.AddRange(properties.Select(property => new ApiResourceProperty(property.Key, property.Value))); | ||
} | ||
|
||
public void BindApiScopes(List<int> apiScopes) | ||
{ | ||
_apiScopes.Clear(); | ||
_apiScopes.AddRange(apiScopes.Select(id => new ApiResourceScope(id))); | ||
} | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
...uthentication/Masa.BuildingBlocks.Authentication.Oidc.Domain/Entities/ApiResourceClaim.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.Authentication.Oidc.Domain.Entities; | ||
|
||
public class ApiResourceClaim : Entity<int> | ||
{ | ||
public int UserClaimId { get; private set; } | ||
|
||
public UserClaim UserClaim { get; private set; } = null!; | ||
|
||
public int ApiResourceId { get; private set; } | ||
|
||
public ApiResource ApiResource { get; private set; } = null!; | ||
|
||
public ApiResourceClaim(int userClaimId) | ||
{ | ||
UserClaimId = userClaimId; | ||
} | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
...entication/Masa.BuildingBlocks.Authentication.Oidc.Domain/Entities/ApiResourceProperty.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.Authentication.Oidc.Domain.Entities; | ||
|
||
public class ApiResourceProperty : Property | ||
{ | ||
public int ApiResourceId { get; private set; } | ||
|
||
public ApiResource ApiResource { get; private set; } = null!; | ||
|
||
public ApiResourceProperty(string key, string value) | ||
{ | ||
Key = key; | ||
Value = value; | ||
} | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
...uthentication/Masa.BuildingBlocks.Authentication.Oidc.Domain/Entities/ApiResourceScope.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.Authentication.Oidc.Domain.Entities; | ||
|
||
public class ApiResourceScope : Entity<int> | ||
{ | ||
public int ApiScopeId { get; private set; } | ||
|
||
public ApiScope ApiScope { get; private set; } = null!; | ||
|
||
public int ApiResourceId { get; private set; } | ||
|
||
public ApiResource ApiResource { get; private set; } = null!; | ||
|
||
public ApiResourceScope(int apiScopeId) | ||
{ | ||
ApiScopeId = apiScopeId; | ||
} | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
...thentication/Masa.BuildingBlocks.Authentication.Oidc.Domain/Entities/ApiResourceSecret.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.BuildingBlocks.Authentication.Oidc.Domain.Entities; | ||
|
||
public class ApiResourceSecret : Secret | ||
{ | ||
public int ApiResourceId { get; private set; } | ||
|
||
public ApiResource ApiResource { get; private set; } = null!; | ||
} | ||
|
Oops, something went wrong.