ABP Framework Consuming HTTP APIs from a .NET Client

A quick example about consuming the generated HTTP APIs from a .NET client using the proxy system provided by the ABP Framework

Jan Hoefnagels 8 weeks ago

I have just tried to accomplish a connection from the console test app following the instructions in the video but I this error: Volo.Abp.AbpException: Could not get token from the OpenId Connect server! ErrorType: Http. Error: Unauthorized. ErrorDescription: The specified 'client_id' is invalid.. HttpStatusCode: Unauthorized

Pity that this video nor the API client documentation contain any details about how to authorize a client proxy

Bart Van Hoey 3 weeks ago

@Jan Hoefnagels

  1. Add BookStore_App section int BookStore.DbMigrator\appsettings.json

"BookStore_App": { "ClientId": "BookStore_App", "ClientSecret": "1q2w3e*", "RootUrl": "https://localhost:44333" }

  1. Add Client in BookStore.Domain\OpenIddict\OpenIddictDataSeedContributor.cs

// BookStoreApp Client var bookStoreAppClientId = configurationSection["BookStore_App:ClientId"]; if (!bookStoreAppClientId.IsNullOrWhiteSpace()) { var bookStoreAppRootUrl = configurationSection["BookStore_App:RootUrl"]?.TrimEnd('/'); await CreateApplicationAsync( name: bookStoreAppClientId, type: OpenIddictConstants.ClientTypes.Confidential, consentType: OpenIddictConstants.ConsentTypes.Implicit, displayName: "BookStoreApp", scopes: commonScopes, grantTypes: [ OpenIddictConstants.GrantTypes.Password, ], secret: configurationSection["BookStore_App:ClientSecret"] ?? "1q2w3e*", redirectUri: $"{bookStoreAppRootUrl}/authentication/login-callback" ); }

  1. Run DbMigrator project

  2. Add ClientSecret to BookStore\test\BookStore.HttpApi.Client.ConsoleTestApp\appsettings.json

{ "RemoteServices": { "Default": { "BaseUrl": "https://localhost:44333" } }, "IdentityClients": { "Default": { "GrantType": "password", "ClientId": "BookStore_App", "UserName": "admin", "UserPassword": "1q2w3E*", "ClientSecret": "1q2w3e*", "Authority": "https://localhost:44333", "Scope": "BookStore" } } }

5 Run API and test again