Starts in:
2 DAYS
9 HRS
8 MIN
52 SEC
Starts in:
2 D
9 H
8 M
52 S
Open Closed

How to call an authorized app service method in background worker #5210


User avatar
0
duyan11110 created
  • ABP Framework version: 7.0.3
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace: Could not retrieve the OpenId Connect discovery document! ErrorType: Exception. Error: Error connecting to http://authserver:7000/.well-known/openid-configuration. HTTPS required. Volo.Abp.AbpException: Could not retrieve the OpenId Connect discovery document! ErrorType: Exception. Error: Error connecting to http:/authserver:7000/.well-known/openid-configuration. HTTPS required. at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.GetDiscoveryResponse(IdentityClientConfiguration configuration) at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.CreateClientCredentialsTokenRequestAsync(IdentityClientConfiguration configuration) at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.GetTokenResponse(IdentityClientConfiguration configuration) at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.GetAccessTokenAsync(IdentityClientConfiguration configuration) at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.GetAccessTokenOrNullAsync(String identityClientName) at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.TryAuthenticateAsync(HttpClient client, String identityClientName) at Volo.Abp.Http.Client.IdentityModel.IdentityModelRemoteServiceHttpClientAuthenticator.Authenticate(RemoteServiceHttpClientAuthenticateContext context) at Volo.Abp.Http.Client.IdentityModel.Web.HttpContextIdentityModelRemoteServiceHttpClientAuthenticator.Authenticate(RemoteServiceHttpClientAuthenticateContext context) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync(ClientProxyRequestContext requestContext) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](ClientProxyRequestContext requestContext) at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments) at MyService.TransactionReports.TransactionReportClientProxy.GenerateReportFileAsync() in ...\MyService.HttpApi.Client\ClientProxies\TransactionReportClientProxy.Generated.cs:line 150 at BackgroundWorker.MyService.ScanErrorFileWorker.SendReportFile() in ...\apps\background-workers\src\BackgroundWorker\MyService\ScanErrorFileWorker.cs:line 86 at BackgroundWorker.MyService.ScanErrorFileWorker.Execute(IJobExecutionContext context) in ...\apps\background-workers\src\BackgroundWorker\MyService\ScanErrorFileWorker.cs

Steps to reproduce the issue: I'm using Quartz background worker to call an authorized app service method with above error. Here's appsettings.json:

"RemoteServices": {
    "MyService": {
      "BaseUrl": "http://myservice.httpapi.host:7005/",
      "UseCurrentAccessToken": "false"
    }
  },
  "IdentityClients": {
    "Default": {
      "GrantType": "client_credentials",
      "ClientId": "BackgroundWorker.DockerHttp",
      "ClientSecret": "1q2w3e*",
      "Authority": "http://authserver:7000",
      "Scope": "MyService"
    }
  }
[DependsOn(
    typeof(AbpAutofacModule),
    typeof(AbpBackgroundWorkersQuartzModule),
	typeof(AbpHttpClientIdentityModelWebModule),
	typeof(AbpIdentityHttpApiClientModule),
	...
)]
public class BackgroundWorkerModule : AbpModule
{
    public override Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
    {
        var logger = context.ServiceProvider.GetRequiredService<ILogger<BackgroundWorkerModule>>();
        var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
        logger.LogInformation($"MySettingName => {configuration["MySettingName"]}");

        var hostEnvironment = context.ServiceProvider.GetRequiredService<IHostEnvironment>();
        logger.LogInformation($"EnvironmentName => {hostEnvironment.EnvironmentName}");

        return Task.CompletedTask;
    }
}

OpenIdDictDataSeeder.cs

//Background Worker
await CreateApplicationAsync(
	name: "BackgroundWorker.DockerHttp",
	type: OpenIddictConstants.ClientTypes.Confidential,
	consentType: OpenIddictConstants.ConsentTypes.Implicit,
	displayName: "Background Worker",
	secret: "1q2w3e*",
	grantTypes: new List<string>
	{
		OpenIddictConstants.GrantTypes.ClientCredentials
	},
	
	scopes: commonScopes.Union(new[] { "MyService" }).ToList(),
	permissions: new List<string> { MyServicePermissions.TransactionReports.Default, MyServicePermissions.TransactionReports.GenerateFile }
);

How can I fix it? Thank you.


4 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Error: Error connecting to http:/authserver:7000/.well-known/openid-configuration. HTTPS required.

    You need to use HTTPS.

  • User Avatar
    0
    duyan11110 created

    I use HTTP not HTTPS. In AdministrationService, it has the same setting and work fine (no need HTTPS).

    "AuthServer": {
        "Authority": "http://authserver:7000",
        "RequireHttpsMetadata": "false",
        "SwaggerClientId": "WebGateway_Swagger.DockerHttp"
      },
      "RemoteServices": {
        "AbpIdentity": {
          "BaseUrl": "http://identityservice.httpapi.host:7002/",
          "UseCurrentAccessToken": "false"
        }
      },
      "IdentityClients": {
        "Default": {
          "GrantType": "client_credentials",
          "ClientId": "AdministrationService.DockerHttp",
          "ClientSecret": "1q2w3e*",
          "Authority": "http://authserver:7000",
          "Scope": "IdentityService"
        }
      },
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I'm not sure about your project details. you can set the RequireHttps to false if you want to use HTTP.

    "IdentityClients": {
        "Default": {
          "GrantType": "client_credentials",
          "ClientId": "BackgroundWorker.DockerHttp",
          "ClientSecret": "1q2w3e*",
          "Authority": "http://authserver:7000",
          "Scope": "MyService",
          "RequireHttps": false
        }
    
  • User Avatar
    0
    duyan11110 created

    Hi,

    Thank you so much for your prompt support. It works now.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06