-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Bearer error="invalid_token" #21265
Comments
Please check this document https://abp.io/docs/latest/solution-templates/layered-web-application/deployment/deployment-docker-compose
|
It still doesn't work after adding if (!hostingEnvironment.IsDevelopment())
{
PreConfigure<AbpOpenIddictAspNetCoreOptions>(options =>
{
options.AddDevelopmentEncryptionAndSigningCertificate = false;
});
PreConfigure<OpenIddictServerBuilder>(serverBuilder =>
{
serverBuilder.AddProductionEncryptionAndSigningCertificate("openiddict.pfx", "aeef0d8c-7288-4d0c-9454-72338dd8111c");
serverBuilder.SetIssuer(new Uri(configuration["AuthServer:Authority"]));
});
} docker-compose.yml authserver:
image: reg.biw.com/im/main/authserver:latest
container_name: authserver
build:
context: .
dockerfile: src/Jee.Im.System.AuthServer/Dockerfile
environment:
- ASPNETCORE_URLS=https://+:443;http://+:80;
- Kestrel__Certificates__Default__Path=/root/certificate/localhost.pfx
- Kestrel__Certificates__Default__Password=91f91912-5ab0-49df-8166-23377efaf3cc
- App__SelfUrl=https://localhost:5200
- App__CorsOrigins=https://localhost:5201,https://localhost:5202,https://localhost:5203,https://localhost:5204,https://localhost:5601,http://localhost:5602,http://localhost:5603,http://localhost:5604
- App__RedirectAllowedUrls=https://localhost:5201,https://localhost:5202,https://localhost:5203,https://localhost:5204,https://localhost:5601,http://localhost:5602,http://localhost:5603,http://localhost:5604
- AuthServer__Authority=https://localhost:5200/
- ConnectionStrings__Default=Server=mysql;Port=3306;Database=im_system;Uid=root;Pwd=123456
- Redis__Configuration=redis
ports:
- "5200:443"
depends_on:
- mysql
- redis
restart: on-failure
volumes:
- ./certs:/root/certificate
system-api:
image: reg.biw.com/im/main/system-api:latest
container_name: system-api
hostname: system-api
build:
context: .
dockerfile: src/Jee.Im.System.HttpApi/Host/Dockerfile
environment:
- ASPNETCORE_URLS=https://+:443;http://+:80;
- Kestrel__Certificates__Default__Path=/root/certificate/localhost.pfx
- Kestrel__Certificates__Default__Password=91f91912-5ab0-49df-8166-23377efaf3cc
- App__SelfUrl=https://localhost:5201
- App__CorsOrigins=https://localhost:5601
- AuthServer__Authority=https://localhost:5200/
- AuthServer__RequireHttpsMetadata=true
- AuthServer__SwaggerClientId=System_Swagger
- ConnectionStrings__Default=Server=mysql;Port=3306;Database=im_system;Uid=root;Pwd=123456
- Redis__Configuration=redis
ports:
- "5201:443"
depends_on:
- mysql
- redis
restart: on-failure
volumes:
- ./certs:/root/certificate |
Please check and share your app error logs. |
The log of server system-api as below: 2024-11-06 14:03:14 [06:03:14 INF] Request starting HTTP/2 GET https://localhost:5201/abp/Swashbuckle/SetCsrfCookie - null null
2024-11-06 14:03:14 [06:03:14 INF] Failed to validate the token.
2024-11-06 14:03:14 Microsoft.IdentityModel.Tokens.SecurityTokenInvalidIssuerException: IDX10204: Unable to validate issuer. validationParameters.ValidIssuer is null or whitespace AND validationParameters.ValidIssuers is null or empty.
2024-11-06 14:03:14 at Microsoft.IdentityModel.Tokens.Validators.ValidateIssuerAsync(String issuer, SecurityToken securityToken, TokenValidationParameters validationParameters, BaseConfiguration configuration)
2024-11-06 14:03:14 at Microsoft.IdentityModel.Tokens.Validators.ValidateIssuer(String issuer, SecurityToken securityToken, TokenValidationParameters validationParameters, BaseConfiguration configuration)
2024-11-06 14:03:14 at Microsoft.IdentityModel.Tokens.InternalValidators.ValidateAfterSignatureFailed(SecurityToken securityToken, Nullable`1 notBefore, Nullable`1 expires, IEnumerable`1 audiences, TokenValidationParameters validationParameters, BaseConfiguration configuration)
2024-11-06 14:03:14 at Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ValidateSignature(JsonWebToken jwtToken, TokenValidationParameters validationParameters, BaseConfiguration configuration)
2024-11-06 14:03:14 at Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ValidateSignatureAndIssuerSecurityKey(JsonWebToken jsonWebToken, TokenValidationParameters validationParameters, BaseConfiguration configuration)
2024-11-06 14:03:14 at Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ValidateJWSAsync(JsonWebToken jsonWebToken, TokenValidationParameters validationParameters, BaseConfiguration configuration)
2024-11-06 14:03:14 [06:03:14 INF] Bearer was not authenticated. Failure message: IDX10204: Unable to validate issuer. validationParameters.ValidIssuer is null or whitespace AND validationParameters.ValidIssuers is null or empty.
2024-11-06 14:03:15 [06:03:14 INF] Executing endpoint 'Volo.Abp.Swashbuckle.AbpSwashbuckleController.SetCsrfCookie (Volo.Abp.Swashbuckle)'
2024-11-06 14:03:15 [06:03:15 INF] Route matched with {area = "Abp", action = "SetCsrfCookie", controller = "AbpSwashbuckle", page = ""}. Executing controller action with signature Void SetCsrfCookie() on controller Volo.Abp.Swashbuckle.AbpSwashbuckleController (Volo.Abp.Swashbuckle).
2024-11-06 14:03:15 [06:03:15 INF] Executed action Volo.Abp.Swashbuckle.AbpSwashbuckleController.SetCsrfCookie (Volo.Abp.Swashbuckle) in 16.8575ms
2024-11-06 14:03:15 [06:03:15 INF] Executed endpoint 'Volo.Abp.Swashbuckle.AbpSwashbuckleController.SetCsrfCookie (Volo.Abp.Swashbuckle)'
2024-11-06 14:03:15 [06:03:15 INF] Request finished HTTP/2 GET https://localhost:5201/abp/Swashbuckle/SetCsrfCookie - 204 null null 107.9089ms
2024-11-06 14:03:15 [06:03:15 INF] Request starting HTTP/2 GET https://localhost:5201/api/identity/roles/all - null null
2024-11-06 14:03:15 [06:03:15 INF] Failed to validate the token.
2024-11-06 14:03:15 Microsoft.IdentityModel.Tokens.SecurityTokenInvalidIssuerException: IDX10204: Unable to validate issuer. validationParameters.ValidIssuer is null or whitespace AND validationParameters.ValidIssuers is null or empty.
2024-11-06 14:03:15 at Microsoft.IdentityModel.Tokens.Validators.ValidateIssuerAsync(String issuer, SecurityToken securityToken, TokenValidationParameters validationParameters, BaseConfiguration configuration)
2024-11-06 14:03:15 at Microsoft.IdentityModel.Tokens.Validators.ValidateIssuer(String issuer, SecurityToken securityToken, TokenValidationParameters validationParameters, BaseConfiguration configuration)
2024-11-06 14:03:15 at Microsoft.IdentityModel.Tokens.InternalValidators.ValidateAfterSignatureFailed(SecurityToken securityToken, Nullable`1 notBefore, Nullable`1 expires, IEnumerable`1 audiences, TokenValidationParameters validationParameters, BaseConfiguration configuration)
2024-11-06 14:03:15 at Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ValidateSignature(JsonWebToken jwtToken, TokenValidationParameters validationParameters, BaseConfiguration configuration)
2024-11-06 14:03:15 at Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ValidateSignatureAndIssuerSecurityKey(JsonWebToken jsonWebToken, TokenValidationParameters validationParameters, BaseConfiguration configuration)
2024-11-06 14:03:15 at Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ValidateJWSAsync(JsonWebToken jsonWebToken, TokenValidationParameters validationParameters, BaseConfiguration configuration)
2024-11-06 14:03:15 [06:03:15 INF] Bearer was not authenticated. Failure message: IDX10204: Unable to validate issuer. validationParameters.ValidIssuer is null or whitespace AND validationParameters.ValidIssuers is null or empty.
2024-11-06 14:03:15 [06:03:15 INF] Executing endpoint 'Volo.Abp.Identity.IdentityRoleController.GetAllListAsync (Volo.Abp.Identity.HttpApi)'
2024-11-06 14:03:15 [06:03:15 INF] Route matched with {area = "identity", controller = "Role", action = "GetAllList", page = ""}. Executing controller action with signature System.Threading.Tasks.Task`1[Volo.Abp.Application.Dtos.ListResultDto`1[Volo.Abp.Identity.IdentityRoleDto]] GetAllListAsync() on controller Volo.Abp.Identity.IdentityRoleController (Volo.Abp.Identity.HttpApi).
2024-11-06 14:03:15 [06:03:15 INF] Authorization failed. These requirements were not met:
2024-11-06 14:03:15 PermissionRequirement: AbpIdentity.Roles
2024-11-06 14:03:15 [06:03:15 WRN] ---------- RemoteServiceErrorInfo ----------
2024-11-06 14:03:15 {
2024-11-06 14:03:15 "code": "Volo.Authorization:010001",
2024-11-06 14:03:15 "message": "授权失败!提供的策略尚未授予。",
2024-11-06 14:03:15 "details": null,
2024-11-06 14:03:15 "data": {},
2024-11-06 14:03:15 "validationErrors": null
2024-11-06 14:03:15 }
2024-11-06 14:03:15
2024-11-06 14:03:15 [06:03:15 WRN] Exception of type 'Volo.Abp.Authorization.AbpAuthorizationException' was thrown.
2024-11-06 14:03:15 Volo.Abp.Authorization.AbpAuthorizationException: Exception of type 'Volo.Abp.Authorization.AbpAuthorizationException' was thrown.
2024-11-06 14:03:15 at Microsoft.AspNetCore.Authorization.AbpAuthorizationServiceExtensions.CheckAsync(IAuthorizationService authorizationService, AuthorizationPolicy policy)
2024-11-06 14:03:15 at Volo.Abp.Authorization.MethodInvocationAuthorizationService.CheckAsync(MethodInvocationAuthorizationContext context)
2024-11-06 14:03:15 at Volo.Abp.Authorization.AuthorizationInterceptor.AuthorizeAsync(IAbpMethodInvocation invocation)
2024-11-06 14:03:15 at Volo.Abp.Authorization.AuthorizationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
2024-11-06 14:03:15 at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
2024-11-06 14:03:15 at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
2024-11-06 14:03:15 at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
2024-11-06 14:03:15 at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
2024-11-06 14:03:15 at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
2024-11-06 14:03:15 at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
2024-11-06 14:03:15 at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
2024-11-06 14:03:15 at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
2024-11-06 14:03:15 at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
2024-11-06 14:03:15 at lambda_method2028(Closure, Object)
2024-11-06 14:03:15 at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
2024-11-06 14:03:15 at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
2024-11-06 14:03:15 at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
2024-11-06 14:03:15 at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
2024-11-06 14:03:15 at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
2024-11-06 14:03:15 at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
2024-11-06 14:03:15 --- End of stack trace from previous location ---
2024-11-06 14:03:15 at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
2024-11-06 14:03:15 [06:03:15 WRN] Code:Volo.Authorization:010001
2024-11-06 14:03:15 [06:03:15 INF] AuthenticationScheme: Bearer was challenged.
2024-11-06 14:03:15 [06:03:15 INF] Executed action Volo.Abp.Identity.IdentityRoleController.GetAllListAsync (Volo.Abp.Identity.HttpApi) in 184.9514ms
2024-11-06 14:03:15 [06:03:15 INF] Executed endpoint 'Volo.Abp.Identity.IdentityRoleController.GetAllListAsync (Volo.Abp.Identity.HttpApi)'
2024-11-06 14:03:15 [06:03:15 INF] Request finished HTTP/2 GET https://localhost:5201/api/identity/roles/all - 401 0 null 432.3762ms
|
See |
Thanks @maliming, I figured it out by adding this code to the services, adding the auth server on the list of valid issuers: options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
{
ValidIssuers = [configuration["AuthServer:Authority"]!.EnsureEndsWith('/')],
SignatureValidator = (token, parameters) => new JsonWebToken(token)
}; But I still wandering why this problem didn't occur when deploying these servers in IIS? |
Another error occured in 2024-11-06 16:15:41 [08:15:41 INF] Request starting HTTP/2 GET https://localhost:5601/ - null null docker-compose.yml: system-web:
image: reg.biw.com/im/main/system-web:latest
container_name: system-web
build:
context: ../../
dockerfile: Jee.Im.System/src/Jee.Im.System.Web/Dockerfile
environment:
- ASPNETCORE_URLS=https://+:443;http://+:80;
- Kestrel__Certificates__Default__Path=/root/certificate/localhost.pfx
- Kestrel__Certificates__Default__Password=91f91912-5ab0-49df-8166-23377efaf3cc
- App__SelfUrl=https://localhost:5601
- RemoteServices__Default__BaseUrl=http://system-api
- AuthServer__Authority=https://localhost:5200/
- AuthServer__RequireHttpsMetadata=false
- AuthServer__ClientId=System_Web
- AuthServer__ClientSecret=1q2w3e*
- AuthServer__IsContainerized=true
- AuthServer__MetaAddress=https://localhost:5200/
- ConnectionStrings__Default=Server=mysql;Port=3306;Database=im_system;Uid=root;Pwd=123456
- Redis__Configuration=redis
ports:
- "5601:443"
restart: on-failure
volumes:
- ./certs:/root/certificate |
I created a layered project based on ABP Framework 8.2 and deployed it to the local environment using Docker Desktop.
When I call the API in Swagger, an error occurs.
The Dockerfile files for several projects are as follows:
The
docker-compose.yml
file:Run docker-compose to start the project, and access https://localhost:5201/swagger/index.html.
The text was updated successfully, but these errors were encountered: