microsoft/healthcare-shared-components
Publicmirrored from https://github.com/microsoft/healthcare-shared-componentsAvailable
src/Microsoft.Health.Client/readme.md
41lines · modecode
| 1 | # Microsoft.Health.Client |
| 2 | |
| 3 | The purpose of this library is to serve as the base for creating web clients that target the various Microsoft Azure Health Data Services. |
| 4 | |
| 5 | ## Example Authenticated Usage |
| 6 | |
| 7 | Configuration |
| 8 | ```json |
| 9 | { |
| 10 | "Dicom": { |
| 11 | "Endpoint": "https://localhost:63838", |
| 12 | "Authentication": { |
| 13 | "Enabled": true, |
| 14 | "AuthenticationType": "OAuth2ClientCredential", |
| 15 | "OAuth2ClientCredential": { |
| 16 | "TokenUri": "https://localhost:63838/connect/token", |
| 17 | "Resource": "health-api", |
| 18 | "Scope": "health-api", |
| 19 | "ClientId": "globalAdminServicePrincipal", |
| 20 | "ClientSecret": "globalAdminServicePrincipal" |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | ``` |
| 26 | |
| 27 | Registration Code |
| 28 | ```csharp |
| 29 | IConfigurationSection dicomWebConfigurationSection = _configuration.GetSection("Dicom"); |
| 30 | services.AddOptions<DicomWebConfiguration>().Bind(dicomWebConfigurationSection); |
| 31 | |
| 32 | services.AddHttpClient<IDicomWebClient, DicomWebClient>((sp, client) => |
| 33 | { |
| 34 | DicomWebConfiguration config = sp.GetRequiredService<IOptions<DicomWebConfiguration>>().Value; |
| 35 | client.BaseAddress = config.Endpoint; |
| 36 | }) |
| 37 | .AddPolicyHandler(retryPolicy) |
| 38 | .AddAuthenticationHandler(dicomWebConfigurationSection.GetSection(AuthenticationConfiguration.SectionName)); |
| 39 | ``` |
| 40 | |
| 41 | > Note: If you wish to register multiple of the same type of client with different configurations, you will need to provide a `name` to the `AddHttpClient` extension. |
| 42 | |