|
| 1 | +# PharmaNet API Client Example |
| 2 | + |
| 3 | +This project is an example implementation of a client for the PharmaNet API. The PharmaNet API provides access to pharmaceutical data and services, and this client demonstrates how to authenticate and interact with it. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The primary focus of this example is on setting up authorization, which is often the most challenging aspect of integrating with the PharmaNet API. Once authenticated, making API calls becomes straightforward. The code includes: |
| 8 | + |
| 9 | +- **Authentication Service**: Handles OAuth2/OpenID Connect flows to obtain access tokens |
| 10 | +- **JWT Handling**: Manages JSON Web Tokens for secure communication |
| 11 | +- **API Integration**: Demonstrates how to make calls to PharmaNet endpoints |
| 12 | +- **FHIR Support**: Includes message formatting for FHIR (Fast Healthcare Interoperability Resources) standard |
| 13 | + |
| 14 | +## Prerequisites |
| 15 | + |
| 16 | +- .NET 6.0 or later |
| 17 | +- Access to PharmaNet API credentials (client ID, client secret, etc.) |
| 18 | +- Valid certificates for JWT signing (see `keygen.sh` for key generation) |
| 19 | + |
| 20 | +## Setup |
| 21 | + |
| 22 | +1. **Clone the repository**: |
| 23 | + ```bash |
| 24 | + git clone <repository-url> |
| 25 | + cd PharmaNetAPIs/Client |
| 26 | + ``` |
| 27 | + |
| 28 | +2. **Configure settings**: |
| 29 | + - Update `src/appsettings.json` with your PharmaNet API credentials |
| 30 | + - Ensure certificate paths are correctly set in the configuration |
| 31 | + |
| 32 | +3. **Generate keys** (if needed): |
| 33 | + ```bash |
| 34 | + cd src |
| 35 | + ./keygen.sh |
| 36 | + ``` |
| 37 | + |
| 38 | +4. **Restore dependencies**: |
| 39 | + ```bash |
| 40 | + dotnet restore |
| 41 | + ``` |
| 42 | + |
| 43 | +5. **Build the project**: |
| 44 | + ```bash |
| 45 | + dotnet build |
| 46 | + ``` |
| 47 | + |
| 48 | +## Usage |
| 49 | + |
| 50 | +Run the application: |
| 51 | + |
| 52 | +```bash |
| 53 | +dotnet run --project src/Client.csproj |
| 54 | +``` |
| 55 | + |
| 56 | +The application will: |
| 57 | +1. Authenticate with the PharmaNet API using the configured credentials |
| 58 | +2. Obtain an access token |
| 59 | +3. Demonstrate making API calls to PharmaNet services |
| 60 | + |
| 61 | +## Project Structure |
| 62 | + |
| 63 | +- `src/Program.cs`: Main entry point |
| 64 | +- `src/Models/`: Data models for API responses and configuration |
| 65 | + - `AccessTokenResponse.cs`: Token response structure |
| 66 | + - `JwtResponse.cs`: JWT response handling |
| 67 | + - `OidcConfiguration.cs`: OpenID Connect configuration |
| 68 | + - `FHIRMessageFormat.cs`: FHIR message formatting |
| 69 | +- `src/Services/`: Core business logic |
| 70 | + - `AuthService.cs`: Authentication implementation |
| 71 | + - `PharmanetService.cs`: PharmaNet API integration |
| 72 | + - `PostService.cs`: HTTP POST operations |
| 73 | +- `src/appsettings.json`: Configuration file |
| 74 | +- `src/keygen.sh`: Script for generating cryptographic keys |
| 75 | + |
| 76 | +## Configuration |
| 77 | + |
| 78 | +Key settings in `appsettings.json`: |
| 79 | + |
| 80 | +- `PharmaNet`: API endpoints and credentials |
| 81 | +- `JwtSigning`: Certificate configuration for JWT signing |
| 82 | +- `OpenIdConnect`: OIDC provider settings |
| 83 | + |
| 84 | +## Troubleshooting |
| 85 | + |
| 86 | +- **Authentication failures**: Verify credentials and certificate validity |
| 87 | +- **API errors**: Check network connectivity and API endpoint URLs |
| 88 | +- **Certificate issues**: Ensure certificates are properly installed and paths are correct |
| 89 | + |
| 90 | +## Contributing |
| 91 | + |
| 92 | +This is an example project. For production use, ensure proper security practices, error handling, and logging are implemented. |
| 93 | + |
| 94 | +## License |
| 95 | + |
| 96 | +[Specify license if applicable] |
0 commit comments