238 lines
5.3 KiB
Markdown
238 lines
5.3 KiB
Markdown
# IronServices.Client
|
|
|
|
Unified client for Iron Services APIs with session-based authentication. Access IronLicensing, IronNotify, and IronTelemetry from a single authenticated client.
|
|
|
|
[](https://www.nuget.org/packages/IronServices.Client)
|
|
[](https://opensource.org/licenses/MIT)
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
dotnet add package IronServices.Client
|
|
```
|
|
|
|
## Quick Start
|
|
|
|
```csharp
|
|
using IronServices.Client;
|
|
|
|
// Create client
|
|
var client = new IronServicesClient(new IronServicesClientOptions
|
|
{
|
|
LicensingUrl = "https://ironlicensing.com",
|
|
NotifyUrl = "https://ironnotify.com",
|
|
TelemetryUrl = "https://irontelemetry.com"
|
|
});
|
|
|
|
// Login
|
|
var loginResult = await client.LoginAsync("user@example.com", "password");
|
|
|
|
if (loginResult.Success)
|
|
{
|
|
Console.WriteLine($"Welcome, {loginResult.DisplayName}!");
|
|
|
|
// Access all Iron Services APIs
|
|
var licenses = await client.Licensing.GetLicensesAsync();
|
|
var events = await client.Notify.GetEventsAsync();
|
|
var errors = await client.Telemetry.GetErrorsAsync();
|
|
}
|
|
```
|
|
|
|
## Authentication
|
|
|
|
### Login
|
|
|
|
```csharp
|
|
var result = await client.LoginAsync("user@example.com", "password");
|
|
|
|
if (result.Success)
|
|
{
|
|
Console.WriteLine($"User ID: {result.UserId}");
|
|
Console.WriteLine($"Role: {result.Role}");
|
|
Console.WriteLine($"Expires: {result.ExpiresAt}");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine($"Login failed: {result.Error}");
|
|
}
|
|
```
|
|
|
|
### Register
|
|
|
|
```csharp
|
|
var result = await client.RegisterAsync(
|
|
email: "newuser@example.com",
|
|
password: "securepassword",
|
|
displayName: "John Doe"
|
|
);
|
|
|
|
if (result.Success)
|
|
{
|
|
Console.WriteLine($"Registered! API Key: {result.ApiKey}");
|
|
}
|
|
```
|
|
|
|
### Email Verification
|
|
|
|
```csharp
|
|
var result = await client.VerifyEmailAsync("user@example.com", "123456");
|
|
|
|
if (result.Success)
|
|
{
|
|
Console.WriteLine("Email verified!");
|
|
}
|
|
```
|
|
|
|
### Password Reset
|
|
|
|
```csharp
|
|
// Request reset email
|
|
await client.RequestPasswordResetAsync("user@example.com");
|
|
|
|
// Reset with token from email
|
|
var result = await client.ResetPasswordAsync(token, "newpassword");
|
|
```
|
|
|
|
### Session Management
|
|
|
|
```csharp
|
|
// Check authentication status
|
|
if (client.IsAuthenticated)
|
|
{
|
|
Console.WriteLine($"Session expires: {client.SessionExpiresAt}");
|
|
}
|
|
|
|
// Get current user profile
|
|
var profile = await client.GetProfileAsync();
|
|
|
|
// Logout
|
|
await client.LogoutAsync();
|
|
```
|
|
|
|
## Token Storage
|
|
|
|
Sessions are persisted automatically. Provide a custom storage for platform-specific secure storage:
|
|
|
|
```csharp
|
|
public class SecureTokenStorage : ITokenStorage
|
|
{
|
|
public async Task SaveTokenAsync(string token, DateTime? expiresAt)
|
|
{
|
|
await SecureStorage.SetAsync("session_token", token);
|
|
if (expiresAt.HasValue)
|
|
await SecureStorage.SetAsync("session_expires", expiresAt.Value.ToString("O"));
|
|
}
|
|
|
|
public async Task<(string? token, DateTime? expiresAt)> GetTokenAsync()
|
|
{
|
|
var token = await SecureStorage.GetAsync("session_token");
|
|
var expiresStr = await SecureStorage.GetAsync("session_expires");
|
|
DateTime? expires = expiresStr != null ? DateTime.Parse(expiresStr) : null;
|
|
return (token, expires);
|
|
}
|
|
|
|
public async Task ClearTokenAsync()
|
|
{
|
|
SecureStorage.Remove("session_token");
|
|
SecureStorage.Remove("session_expires");
|
|
}
|
|
}
|
|
|
|
// Use custom storage
|
|
var client = new IronServicesClient(options, new SecureTokenStorage());
|
|
```
|
|
|
|
## Service APIs
|
|
|
|
### IronLicensing
|
|
|
|
```csharp
|
|
// Get all licenses
|
|
var licenses = await client.Licensing.GetLicensesAsync();
|
|
|
|
// Get license details
|
|
var license = await client.Licensing.GetLicenseAsync(licenseId);
|
|
|
|
// Create license
|
|
var newLicense = await client.Licensing.CreateLicenseAsync(new CreateLicenseRequest
|
|
{
|
|
TierId = tierId,
|
|
CustomerEmail = "customer@example.com"
|
|
});
|
|
```
|
|
|
|
### IronNotify
|
|
|
|
```csharp
|
|
// Get events
|
|
var events = await client.Notify.GetEventsAsync();
|
|
|
|
// Get apps
|
|
var apps = await client.Notify.GetAppsAsync();
|
|
```
|
|
|
|
### IronTelemetry
|
|
|
|
```csharp
|
|
// Get errors
|
|
var errors = await client.Telemetry.GetErrorsAsync();
|
|
|
|
// Get projects
|
|
var projects = await client.Telemetry.GetProjectsAsync();
|
|
```
|
|
|
|
## Configuration
|
|
|
|
```csharp
|
|
var client = new IronServicesClient(new IronServicesClientOptions
|
|
{
|
|
// Service URLs (defaults shown)
|
|
LicensingUrl = "https://ironlicensing.com",
|
|
NotifyUrl = "https://ironnotify.com",
|
|
TelemetryUrl = "https://irontelemetry.com"
|
|
});
|
|
```
|
|
|
|
For local development:
|
|
|
|
```csharp
|
|
var client = new IronServicesClient(new IronServicesClientOptions
|
|
{
|
|
LicensingUrl = "https://localhost:5001",
|
|
NotifyUrl = "https://localhost:5003",
|
|
TelemetryUrl = "https://localhost:5005"
|
|
});
|
|
```
|
|
|
|
## Generic API Methods
|
|
|
|
Make authenticated requests to any endpoint:
|
|
|
|
```csharp
|
|
// GET
|
|
var data = await client.GetAsync<MyResponse>("https://ironlicensing.com/api/v1/custom");
|
|
|
|
// POST
|
|
var result = await client.PostAsync<MyRequest, MyResponse>(
|
|
"https://ironlicensing.com/api/v1/custom",
|
|
new MyRequest { /* ... */ }
|
|
);
|
|
|
|
// PUT
|
|
await client.PutAsync<MyRequest, MyResponse>(url, data);
|
|
|
|
// DELETE
|
|
await client.DeleteAsync(url);
|
|
```
|
|
|
|
## Links
|
|
|
|
- [IronLicensing](https://www.ironlicensing.com)
|
|
- [IronNotify](https://www.ironnotify.com)
|
|
- [IronTelemetry](https://www.irontelemetry.com)
|
|
- [Documentation](https://www.ironlicensing.com/docs)
|
|
|
|
## License
|
|
|
|
MIT License - see [LICENSE](LICENSE) for details.
|