Overview
HGT EAM WebServices uses HTTP Basic Authentication to secure API access. All requests must include valid credentials that are validated against a configured list of authorized users. Additionally, the API enforces rate limiting (60 requests per minute per user) to prevent abuse and ensure fair resource allocation.Authentication Flow
Basic Authentication Implementation
Configuration Setup
Credentials are configured inappsettings.json (or environment variables for production):
appsettings.json
Authentication Extension
The authentication system is configured inAuthorizationExtensions.cs:18-62:
AuthorizationExtensions.cs
User Claims
After successful authentication, the system creates aClaimsPrincipal with the following claims:
The username of the authenticated user (e.g.,
api_user_1)The EAM organization the user belongs to (e.g.,
HGT)The user’s password (stored in claims for passing to downstream EAM SOAP calls)
The password is stored in claims because the API acts as a proxy - it needs to pass credentials to the underlying EAM SOAP service on behalf of the user.
Making Authenticated Requests
Clients must include theAuthorization header with Base64-encoded credentials:
Rate Limiting
Configuration
The API enforces 60 requests per minute per user, configured inStartup.cs:109-168:
Startup.cs
Rate Limit Behavior
Per-User Limits
Per-User Limits
Each authenticated user gets 60 requests per minute independently:
api_user_1: 60 req/minreadonly_user: 60 req/min (separate quota)- Unauthenticated requests: 60 req/min per IP address
Fixed Window Algorithm
Fixed Window Algorithm
The rate limiter uses a fixed window approach:
- Window starts when first request arrives
- Resets after 1 minute
- No sliding window or token bucket
- 12:00:00 - Request 1 (window starts)
- 12:00:30 - Request 60 (quota exhausted)
- 12:00:45 - Request 61 → 429 Too Many Requests
- 12:01:00 - Window resets, quota replenished
429 Response Format
429 Response Format
When rate limit is exceeded, the API returns:The
Retry-After header indicates seconds until quota resets.Handling Rate Limits in Client Code
Security Best Practices
1. Always Use HTTPS
1. Always Use HTTPS
Basic Authentication encodes credentials in Base64, which is not encryption. Without HTTPS, credentials are transmitted in plain text.Configure HTTPS in production:Check certificate configuration:
Startup.cs:45
2. Use Environment Variables for Secrets
2. Use Environment Variables for Secrets
Never hardcode passwords in
appsettings.json. Use environment variables or secret managers:- Docker
- Kubernetes
- Azure Key Vault
docker-compose.yml
.env
3. Rotate Credentials Regularly
3. Rotate Credentials Regularly
Implement a credential rotation policy:
- Create new credentials with a different username
- Add to configuration alongside existing credentials
- Update client applications to use new credentials
- Monitor usage of old credentials
- Remove old credentials after migration period
4. Monitor Authentication Failures
4. Monitor Authentication Failures
The API logs authentication events via Serilog:Monitor for suspicious patterns:
Startup.cs:62-69
- Multiple 401 responses from same IP (brute force attempt)
- 429 responses (rate limit abuse)
- Successful auth followed by unusual request patterns
5. Implement IP Whitelisting (Optional)
5. Implement IP Whitelisting (Optional)
For high-security environments, restrict API access to known IP ranges:
Startup.cs (Add before authentication)
Credential Flow to EAM Services
The API acts as a transparent proxy - user credentials are passed through to the underlying EAM SOAP service: Key Point: The API does not validate EAM credentials - it only checks if the username/password exist in theEAMCredentials configuration. The actual EAM authentication happens when calling the SOAP service.
Troubleshooting
401 Unauthorized
401 Unauthorized
429 Too Many Requests
429 Too Many Requests
Cause: Exceeded 60 requests per minute quota.Solutions:
- Implement retry logic with exponential backoff (see code examples above)
- Reduce request frequency by caching responses client-side
- Use pagination efficiently - don’t request all pages at once
- Contact administrator if limit is insufficient for your use case
500 Internal Server Error (EAM Auth Failure)
500 Internal Server Error (EAM Auth Failure)
If you receive 500 errors after successfully authenticating to the API:Cause: The EAM SOAP service rejected the credentials.Check logs:Common scenarios:
- EAM account is locked
- EAM password has expired
- Organization code is incorrect
- EAM user lacks permissions for the requested grid
Next Steps
Quick Start
Make your first authenticated API request
Architecture Overview
Understand how authentication fits into the system
API Reference
Explore available endpoints and parameters
Setup Guide
Configure authentication in production environments