Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abp generate-proxy -t csharp command fails with ArgumentOutOfRangeException, but abp generate-proxy -t ng works fine #22275

Open
1 task done
jackcodewu opened this issue Mar 5, 2025 · 5 comments
Assignees
Labels

Comments

@jackcodewu
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Description

I am encountering an ArgumentOutOfRangeException when using the abp generate-proxy -t csharp command to generate C# client proxies. This issue occurs with ABP CLI version 0.9.23.
Command: abp generate-proxy -t csharp --folder ClientProsies -url https://localhost:44322/
Error Message (Full Stack Trace):

[15:38:47 INF] You are running the second generation of the ABP CLI. If you're interested in the legacy CLI, see https://abp.io/new-cli
[15:38:47 INF] Create ClientProsies\CustomerBookClientProxy.Generated.cs
[15:38:47 INF] Create ClientProsies\ICustomerBookAppService.cs
[15:38:47 INF] Create ClientProsies\CustomerEnglishWordClientProxy.Generated.cs
[15:38:47 INF] Create ClientProsies\ICustomerEnglishWordAppService.cs
[15:38:47 INF] Create ClientProsies\CustomerClientProxy.Generated.cs
[15:38:47 INF] Create ClientProsies\ICustomerAppService.cs
System.ArgumentOutOfRangeException: length ('-1') must be a non-negative value. (Parameter 'length')
Actual value was -1.
  at void System.ArgumentOutOfRangeException.ThrowNegative(T value, string paramName)
  at void System.ArgumentOutOfRangeException.ThrowIfNegative(T value, string paramName)
  at void System.String.ThrowSubstringArgumentOutOfRange(int startIndex, int length)
  at string System.String.Substring(int startIndex, int length)
  at object Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.WFAIvVOhTRZTfagUEOv(object , int , int )
  at string Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.oB5EsTAqMp(object  )
  at string Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.L6tE2WQdBw(object  , List  )
  at void Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.ynpEnvrBWd(ActionApiDescriptionModel  ,
     string  , StringBuilder  , List  )
  at void Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.A2SEtQqbOi(ActionApiDescriptionModel  ,
     StringBuilder  , List  )
  at async Task Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.bSiECZlSPQ(GenerateProxyArgs  ,
     ControllerApiDescriptionModel  )
  at async Task Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.GenerateProxyAsync(GenerateProxyArgs
     args)
  at async Task Volo.Abp.Cli.Commands.ProxyCommandBase1.ExecuteAsync(CommandLineArgs commandLineArgs)   at async Task Volo.Abp.Studio.Cli.StudioCliService.RunInternalAsync(CommandLineArgs commandLineArgs)   at async Task Volo.Abp.Studio.Cli.StudioCliService.RunAsync(string[] args) Unhandled exception. System.ArgumentOutOfRangeException: length ('-1') must be a non-negative value. (Parameter 'length') Actual value was -1.    at System.ArgumentOutOfRangeException.ThrowNegative[T](T value, String paramName)    at System.ArgumentOutOfRangeException.ThrowIfNegative[T](T value, String paramName)    at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length)    at System.String.Substring(Int32 startIndex, Int32 length)    at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.WFAIvVOhTRZTfagUEOv(Object, Int32, Int32)    at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.oB5EsTAqMp(Object  )    at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.L6tE2WQdBw(Object  , List1  )
   at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.ynpEnvrBWd(ActionApiDescriptionModel  , String  , StringBuilder  , List1  )    at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.A2SEtQqbOi(ActionApiDescriptionModel  , StringBuilder  , List1  )
   at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.bSiECZlSPQ(GenerateProxyArgs  , ControllerApiDescriptionModel  )
   at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.GenerateProxyAsync(GenerateProxyArgs args)
   at Volo.Abp.Cli.Commands.ProxyCommandBase`1.ExecuteAsync(CommandLineArgs commandLineArgs)
   at Volo.Abp.Studio.Cli.StudioCliService.RunInternalAsync(CommandLineArgs commandLineArgs)
   at Volo.Abp.Studio.Cli.StudioCliService.RunAsync(String[] args)
   at Volo.Abp.Studio.Cli.Program.DZOCxkt1y(Object  )
   at Volo.Abp.Studio.Cli.Program.

(String[] args)

Environment:

ABP CLI version: 0.9.23
.NET SDK version: 9.0
OS: Windows 11

Reproduction Steps

Using ABP CLI version 0.9.23.
Run the command abp generate-proxy -t csharp --folder ClientProsies -url https://localhost:44322/ against the specified API endpoint.
Observe the System.ArgumentOutOfRangeException error.

Expected behavior

The abp generate-proxy -t csharp command should successfully generate C# client proxy files in the ClientProsies folder based on the API definition at https://localhost:44322/ when using ABP CLI version 0.9.23.

Actual behavior

Using ABP CLI version 0.9.23, the command fails with a System.ArgumentOutOfRangeException. The stack trace indicates the error originates from Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator, specifically within methods related to string manipulation during C# proxy generation.
Error Message (Full Stack Trace):

[15:38:47 INF] You are running the second generation of the ABP CLI. If you're interested in the legacy CLI, see https://abp.io/new-cli
[15:38:47 INF] Create ClientProsies\CustomerBookClientProxy.Generated.cs
[15:38:47 INF] Create ClientProsies\ICustomerBookAppService.cs
[15:38:47 INF] Create ClientProsies\CustomerEnglishWordClientProxy.Generated.cs
[15:38:47 INF] Create ClientProsies\ICustomerEnglishWordAppService.cs
[15:38:47 INF] Create ClientProsies\CustomerClientProxy.Generated.cs
[15:38:47 INF] Create ClientProsies\ICustomerAppService.cs
System.ArgumentOutOfRangeException: length ('-1') must be a non-negative value. (Parameter 'length')
Actual value was -1.
  at void System.ArgumentOutOfRangeException.ThrowNegative(T value, string paramName)
  at void System.ArgumentOutOfRangeException.ThrowIfNegative(T value, string paramName)
  at void System.String.ThrowSubstringArgumentOutOfRange(int startIndex, int length)
  at string System.String.Substring(int startIndex, int length)
  at object Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.WFAIvVOhTRZTfagUEOv(object , int , int )
  at string Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.oB5EsTAqMp(object  )
  at string Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.L6tE2WQdBw(object  , List  )
  at void Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.ynpEnvrBWd(ActionApiDescriptionModel  ,
     string  , StringBuilder  , List  )
  at void Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.A2SEtQqbOi(ActionApiDescriptionModel  ,
     StringBuilder  , List  )
  at async Task Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.bSiECZlSPQ(GenerateProxyArgs  ,
     ControllerApiDescriptionModel  )
  at async Task Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.GenerateProxyAsync(GenerateProxyArgs
     args)
  at async Task Volo.Abp.Cli.Commands.ProxyCommandBase1.ExecuteAsync(CommandLineArgs commandLineArgs)   at async Task Volo.Abp.Studio.Cli.StudioCliService.RunInternalAsync(CommandLineArgs commandLineArgs)   at async Task Volo.Abp.Studio.Cli.StudioCliService.RunAsync(string[] args) Unhandled exception. System.ArgumentOutOfRangeException: length ('-1') must be a non-negative value. (Parameter 'length') Actual value was -1.    at System.ArgumentOutOfRangeException.ThrowNegative[T](T value, String paramName)    at System.ArgumentOutOfRangeException.ThrowIfNegative[T](T value, String paramName)    at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length)    at System.String.Substring(Int32 startIndex, Int32 length)    at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.WFAIvVOhTRZTfagUEOv(Object, Int32, Int32)    at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.oB5EsTAqMp(Object  )    at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.L6tE2WQdBw(Object  , List1  )
   at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.ynpEnvrBWd(ActionApiDescriptionModel  , String  , StringBuilder  , List1  )    at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.A2SEtQqbOi(ActionApiDescriptionModel  , StringBuilder  , List1  )
   at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.bSiECZlSPQ(GenerateProxyArgs  , ControllerApiDescriptionModel  )
   at Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.GenerateProxyAsync(GenerateProxyArgs args)
   at Volo.Abp.Cli.Commands.ProxyCommandBase`1.ExecuteAsync(CommandLineArgs commandLineArgs)
   at Volo.Abp.Studio.Cli.StudioCliService.RunInternalAsync(CommandLineArgs commandLineArgs)
   at Volo.Abp.Studio.Cli.StudioCliService.RunAsync(String[] args)
   at Volo.Abp.Studio.Cli.Program.DZOCxkt1y(Object  )
   at Volo.Abp.Studio.Cli.Program.

(String[] args)

Regression?

No response

Known Workarounds

Important Note:

Crucially, the command abp generate-proxy -t ng --folder ClientProsies -url https://localhost:44322/ for generating Angular client proxies works perfectly fine against the same API endpoint with ABP CLI version 0.9.23. This clearly demonstrates that the core proxy generation functionality and the API endpoint itself are working correctly. The issue appears to be isolated to the C# proxy generation logic within ABP CLI version 0.9.23.

Possible Root Cause:

It is highly likely that there is a bug within the CSharpServiceProxyGenerator in ABP CLI version 0.9.23. This bug seems to be related to handling string lengths during the C# proxy generation process, potentially triggered by specific patterns in the API definition. The error message length ('-1') must be a non-negative value points towards an issue with substring length calculation in the C# proxy generator for this specific version.

Request:

Please investigate this ArgumentOutOfRangeException error in the abp generate-proxy -t csharp command specifically within ABP CLI version 0.9.23. The successful generation of Angular proxies using abp generate-proxy -t ng against the same API endpoint highlights that the problem is likely confined to the C# proxy generation logic in this specific CLI version. A fix for this issue in ABP CLI version 0.9.23 would be greatly appreciated, or guidance on a compatible ABP CLI version for C# proxy generation with ABP Framework.

Version

abp framework version is 9.0.3, abp cli version is 0.9.23

User Interface

Common (Default)

Database Provider

EF Core (Default)

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

No response

@jackcodewu jackcodewu added the bug label Mar 5, 2025
@realLiangshiwei
Copy link
Member

Share the full reproduce steps. thanks.

@jackcodewu
Copy link
Author

  1. I started the server project
  2. I executed the command abp generate-proxy -t ng in the angular client project and it was successful
  3. I executed abp generate-proxy -t csharp --folder ClientProsies -url https://localhost:44322/ in the .NET MAUI client project and the following error was displayed
    [17:53:11 INF] You are running the second generation of the ABP CLI. If you're interested in the legacy CLI, see https://abp.io/new-cli
    [17:53:11 INF] Create ClientProsies\CustomerBookClientProxy.cs
    [17:53:11 INF] Create ClientProsies\CustomerBookClientProxy.Generated.cs
    [17:53:11 INF] Create ClientProsies\ICustomerBookAppService.cs
    [17:53:11 INF] Create ClientProsies\CustomerEnglishWordClientProxy.cs
    [17:53:11 INF] Create ClientProsies\CustomerEnglishWordClientProxy.Generated.cs
    [17:53:11 INF] Create ClientProsies\ICustomerEnglishWordAppService.cs
    [17:53:11 INF] Create ClientProsies\CustomerClientProxy.cs
    [17:53:11 INF] Create ClientProsies\CustomerClientProxy.Generated.cs
    [17:53:11 INF] Create ClientProsies\ICustomerAppService.cs
    [17:53:11 INF] Create ClientProsies\CustomerAuthClientProxy.cs
    System.ArgumentOutOfRangeException: length ('-1') must be a non-negative value. (Parameter 'length')
    Actual value was -1.
    at void System.ArgumentOutOfRangeException.ThrowNegative(T value, string paramName)
    at void System.ArgumentOutOfRangeException.ThrowIfNegative(T value, string paramName)
    at void System.String.ThrowSubstringArgumentOutOfRange(int startIndex, int length)
    at string System.String.Substring(int startIndex, int length)
    at object Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.WFAIvVOhTRZTfagUEOv(object , int , int )
    at string Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.oB5EsTAqMp(object )
    at string Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.L6tE2WQdBw(object , List )
    at void Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.ynpEnvrBWd(ActionApiDescriptionModel, string, StringBuilder, List)
    at void Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.A2SEtQqbOi(ActionApiDescriptionModel , StringBuilder , List )
    at async Task Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.bSiECZlSPQ(GenerateProxyArgs, ControllerApiDescriptionModel)
    at async Task Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.GenerateProxyAsync(GenerateProxyArgs args)
    at async Task Volo.Abp.Cli.Commands.ProxyCommandBase1.ExecuteAsync(CommandLineArgs commandLineArgs) at async Task Volo.Abp.Studio.Cli.StudioCliService.RunInternalAsync(CommandLineArgs commandLineArgs) at async Task Volo.Abp.Studio.Cli.StudioCliService.RunAsync(string[] args) PS D:\Projects\AbpProjects\NextEnglishMobile\NextEnglishMobile> abp generate-proxy -t csharp --folder ClientProsies -url https://localhost:44322/ [17:53:11 INF] You are running the second generation of the ABP CLI. If you're interested in the legacy CLI, see https://abp.io/new-cli [17:53:11 INF] Create ClientProsies\CustomerBookClientProxy.cs [17:53:11 INF] Create ClientProsies\CustomerBookClientProxy.Generated.cs [17:53:11 INF] Create ClientProsies\ICustomerBookAppService.cs [17:53:11 INF] Create ClientProsies\CustomerEnglishWordClientProxy.cs [17:53:11 INF] Create ClientProsies\CustomerEnglishWordClientProxy.Generated.cs [17:53:11 INF] Create ClientProsies\ICustomerEnglishWordAppService.cs [17:53:11 INF] Create ClientProsies\CustomerClientProxy.cs [17:53:11 INF] Create ClientProsies\CustomerClientProxy.Generated.cs [17:53:11 INF] Create ClientProsies\ICustomerAppService.cs [17:53:11 INF] Create ClientProsies\CustomerAuthClientProxy.cs System.ArgumentOutOfRangeException: length ('-1') must be a non-negative value. (Parameter 'length') Actual value was -1. at void System.ArgumentOutOfRangeException.ThrowNegative<T>(T value, string paramName) at void System.ArgumentOutOfRangeException.ThrowIfNegative<T>(T value, string paramName) at void System.String.ThrowSubstringArgumentOutOfRange(int startIndex, int length) at string System.String.Substring(int startIndex, int length) at object Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.WFAIvVOhTRZTfagUEOv(object , int , int ) at string Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.oB5EsTAqMp(object ) at string Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.L6tE2WQdBw(object , List<string> ) at void Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.ynpEnvrBWd(ActionApiDescriptionModel, string, StringBuilder, List<string>) at void Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.A2SEtQqbOi(ActionApiDescriptionModel , StringBuilder , List<string> ) at async Task Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.bSiECZlSPQ(GenerateProxyArgs , ControllerApiDescriptionModel ) at async Task Volo.Abp.Cli.ServiceProxying.CSharp.CSharpServiceProxyGenerator.GenerateProxyAsync(GenerateProxyArgs args) at async Task Volo.Abp.Cli.Commands.ProxyCommandBase1.ExecuteAsync(CommandLineArgs

@realLiangshiwei
Copy link
Member

This step is not enough to reproduce, usually related to your application service code. Please provide a test project, thanks.

@realLiangshiwei realLiangshiwei self-assigned this Mar 5, 2025
@jackcodewu
Copy link
Author

  1. I added it to the Application project

public class CustomerAuthAppService : ApplicationService, ICustomerAuthAppService
{
private readonly ICustomerManager _customerManager;
private readonly IOpenIddictApplicationManager _applicationManager;
private readonly IOpenIddictAuthorizationManager _authorizationManager;
private readonly IOpenIddictScopeManager _scopeManager;
private readonly IOpenIddictTokenManager _tokenManager;
private readonly IClock _clock;
private readonly IPasswordHasher _passwordHasher;

public CustomerAuthAppService(
ICustomerManager customerManager,
IOpenIddictApplicationManager applicationManager,
IOpenIddictAuthorizationManager authorizationManager,
IOpenIddictScopeManager scopeManager,
IOpenIddictTokenManager tokenManager,
IClock clock,
IPasswordHasher passwordHasher)
{
_customerManager = customerManager;
_applicationManager = applicationManager;
_authorizationManager = authorizationManager;
_scopeManager = scopeManager;
_tokenManager = tokenManager;
_clock = clock;
_passwordHasher = passwordHasher;
}

public async Task LoginAsync(CustomerLoginDto input)
{
var result = await _customerManager.ValidateCredentialsAsync(
input.UserNameOrEmailAddress,
input.Password
);

if (result.Result != CustomerAuthenticationResultType.Success)
{
return new CustomerAuthResultDto
{
Success = false,
Error = "Invalid username or password"
};
}

var customer = result.Customer;

// 3. Create identity information
var identity = new ClaimsIdentity(
authenticationType: TokenValidationParameters.DefaultAuthenticationType,
nameType: Claims.Name,
roleType: Claims.Role);

// 4. Add necessary claims
identity.AddClaim(Claims.Subject, customer.Id.ToString());
identity.AddClaim(Claims.Name, customer.Nickname);
identity.AddClaim(Claims.Email, customer.Email);
identity.AddClaim("phone_number", customer.PhoneNumber); // You can add custom claims

return new CustomerAuthResultDto
{
Success = true,
ClaimsIdentity = identity
};
}

public async Task RegisterAsync(CustomerRegisterDto input)
{
// Verify that the username already exists
var existingUser = await _customerManager.FindByUserNameOrEmailAsync(input.UserName);
if (existingUser != null)
{
return new CustomerAuthResultDto
{
Success = false,
Error = L["UserNameAlreadyExists"]
};
}

// Verify that the email already exists
existingUser = await _customerManager.FindByUserNameOrEmailAsync(input.Email);
if (existingUser != null)
{
return new CustomerAuthResultDto
{
Success = false,
Error = L["EmailAlreadyExists"]
};
}

try
{
var customer= await _customerManager.CreateAsync(
input.UserName,
input.Password,
input.Email,
input.PhoneNumber,
input.BirthDate,
input.Nickname
);

// 3. Create identity information
var identity = new ClaimsIdentity(
authenticationType: TokenValidationParameters.DefaultAuthenticationType,
nameType: Claims.Name,
roleType: Claims.Role);

// 4. Add necessary claims
identity.AddClaim(Claims.Subject, customer.Id.ToString());
identity.AddClaim(Claims.Name, customer.Nickname);
identity.AddClaim(Claims.Email, customer.Email);
identity.AddClaim("phone_number", customer.PhoneNumber); // You can add custom claims

// 5. Set scopes
//identity.SetScopes(request.GetScopes());

return new CustomerAuthResultDto
{
Success = true,
ClaimsIdentity = identity
};
}
catch (Exception ex)
{
return new CustomerAuthResultDto
{
Success = false,
Error = ex.Message
};
}
}
}

  1. Then add the following interface to the Application.Contracts project
    {
    public interface ICustomerAuthAppService : IApplicationService
    {
    Task LoginAsync(CustomerLoginDto input);
    Task RegisterAsync(CustomerRegisterDto input);
    }

  2. An error occurred when executing the following command

abp generate-proxy -t csharp -u https://localhost:44322/

  1. DTO and Entity to be used in the future
    public class CustomerLoginDto
    {
    [Required]
    public string UserNameOrEmailAddress { get; set; }

[Required]
public string Password { get; set; }
public bool RememberMe { get; set; }
}

public class CustomerRegisterDto
{
[Required]
[StringLength(50)]
public string UserName { get; set; }

[Required]
[EmailAddress]
[StringLength(200)]
public string Email { get; set; }

[Required]
[StringLength(100)]
[DataType(DataType.Password)]
public string Password { get; set; }

[Required]
[StringLength(100)]
[Compare(nameof(Password))]
public string ConfirmPassword { get; set; }

[Required]
[StringLength(50)]
public string Nickname { get; set; }

[Required]
[Phone]
public string PhoneNumber { get; set; }
public DateTime BirthDate { get; set; }
}
public class CustomerAuthResultDto
{
public bool Success { get; set; }
public ClaimsIdentity ClaimsIdentity { get; set; }
public string Error { get; set; }
public bool RequiresTwoFactor { get; set; }
}

public classCustomer: FullAuditedEntity, ISoftDelete
{
public string UserName { get; set; }
public string PasswordHash { get; set; } // Here we assume that the password is stored in plain text. In actual applications, hash storage should be used
public string Email { get; set; }
public string PhoneNumber { get; set; }
public DateTime DateOfBirth { get; set; }
public bool IsLocked { get; set; } // Locked or not
public string Nickname { get; set; } // Nickname

public virtual CustomerLevel Level { get; set; }

public virtual DateTime? ExpiryDate { get; set; }

public virtual string SecurityStamp { get; protected set; }

public Customer(Guid id, string userName, string password, string email, string phoneNumber, DateTime dateOfBirth, string nickname, CustomerLevel customerLevel, DateTime ExpiryDate)
: base(id)
{
UserName = userName;
PasswordHash = password;
Email = email;
PhoneNumber = phoneNumber;
DateOfBirth = dateOfBirth;
Nickname = nickname;
Level = customerLevel;
this.ExpiryDate = ExpiryDate;
SecurityStamp = Guid.NewGuid().ToString();
}

public virtual void SetPassword(IPasswordHasher passwordHasher, string password)
{
PasswordHash = passwordHasher.HashPassword(this, password);
}

public virtual bool VerifyPassword(IPasswordHasher passwordHasher, string password)
{
return passwordHasher.VerifyHashedPassword(this, PasswordHash, password) != PasswordVerificationResult.Failed;
}

public virtual List GetClaims()
{
var claims = new List
{
// OpenID Connect Standard Claims
new Claim("sub", Id.ToString()), // Required unique identifier
new Claim("name", UserName), // Display name
new Claim("email", Email), // Email

// Custom Claims
new Claim("customer_id", Id.ToString()), // Customer ID
new Claim(ClaimTypes.Role, "customer"), // Role
};

return claims;
}

}

@jackcodewu
Copy link
Author

If remove CustomerAuthAppService and ICustomerAuthAppService,then is work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants