ABP Framework Consuming HTTP APIs from a .NET Client
1、Add BookStore_App section int BookStore.DbMigrator\appsettings.json "BookStore_App": { "ClientId": "BookStore_App", "ClientSecret": "1q2w3e*", "RootUrl": "https://localhost:44333" } 2、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" ); } 3、Run DbMigrator project 4、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
- Add BookStore_App section int BookStore.DbMigrator\appsettings.json
"BookStore_App": { "ClientId": "BookStore_App", "ClientSecret": "1q2w3e*", "RootUrl": "https://localhost:44333" }
- 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" ); }
-
Run DbMigrator project
-
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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】博客园携手 AI 驱动开发工具商 Chat2DB 推出联合终身会员
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步