SeliseBlocks.Ecohub.SAF
1.0.0-beta.6
dotnet add package SeliseBlocks.Ecohub.SAF --version 1.0.0-beta.6
NuGet\Install-Package SeliseBlocks.Ecohub.SAF -Version 1.0.0-beta.6
<PackageReference Include="SeliseBlocks.Ecohub.SAF" Version="1.0.0-beta.6" />
<PackageVersion Include="SeliseBlocks.Ecohub.SAF" Version="1.0.0-beta.6" />
<PackageReference Include="SeliseBlocks.Ecohub.SAF" />
paket add SeliseBlocks.Ecohub.SAF --version 1.0.0-beta.6
#r "nuget: SeliseBlocks.Ecohub.SAF, 1.0.0-beta.6"
#addin nuget:?package=SeliseBlocks.Ecohub.SAF&version=1.0.0-beta.6&prerelease
#tool nuget:?package=SeliseBlocks.Ecohub.SAF&version=1.0.0-beta.6&prerelease
SeliseBlocks.Ecohub.SAF
Overview
SeliseBlocks.Ecohub.SAF
is a .NET library for integrating with the SAF (Secure Access Facility) platform. It provides comprehensive services for:
- Authentication and token management
- Public key operations
- Event handling via REST or Kafka
Table of Contents
- Installation
- Getting Started
- Features and Usage
- Generate Public and Private Key
- Response Structure
- Error Handling
- Dependencies
Installation
To install the SeliseBlocks.Ecohub.SAF
library, use the following command:
dotnet add package SeliseBlocks.Ecohub.SAF
Getting Started
Register Dependencies
Before using the library, register its services in your application's dependency injection container:
services.AddSafDriverServices("https://your-saf-api-base-url");
This registers:
ISafAuthService
ISafApiService
ISafRestProxyEventHandler
ISafKafkaEventHandler
Features and Usage
1. Authentication (ISafAuthService
)
All authentication responses have the following structure:
IsSuccess
: Indicates if the operation succeeded.Data
: The result data (type depends on the operation).Error
: Error details if the operation failed.
Tech User Enrolment
Task<SafTechUserEnrolmentResponse> EnrolTechUserAsync(SafTechUserEnrolmentRequest request);
- Request:
SafTechUserEnrolmentRequest
Iak
(required)IdpUserId
(required)LicenceKey
(required)Password
(required)RequestId
RequestTime
UserAgent
- Response:
SafTechUserEnrolmentResponse
IsSuccess
Data
(SafTechUserEnrolment
): ContainsTechUserCert
,OAuth2
credentialsError
(SafError
): Error details if any
Example:
var request = new SafTechUserEnrolmentRequest
{
Iak = "your-iak",
IdpUserId = "your-user-id",
LicenceKey = "your-licence-key",
Password = "your-password",
RequestId = Guid.NewGuid().ToString(),
RequestTime = DateTime.UtcNow.ToString("o"),
UserAgent = new SafUserAgent { Name = "Chrome", Version = "126.0.6478.270" }
};
var response = await authService.EnrolTechUserAsync(request);
if (response.IsSuccess)
{
// response.Data is SafTechUserEnrolment
Console.WriteLine($"Tech User Cert: {response.Data.TechUserCert}");
Console.WriteLine($"Client ID: {response.Data.OAuth2.ClientId}");
}
else
{
// response.Error is SafError
Console.WriteLine($"Error: {response.Error?.ErrorMessage}");
}
Get OpenID Configuration
Task<SafOpenIdConfigurationResponse> GetOpenIdConfigurationAsync(Uri openIdUrl);
- Response:
SafOpenIdConfigurationResponse
IsSuccess
Data
(SafOpenIdConfiguration
): OpenID configurationError
(SafError
)
Retrieve Bearer Token
Task<SafBearerTokenResponse> GetBearerToken(SafBearerTokenRequest request);
- Response:
SafBearerTokenResponse
IsSuccess
Data
(SafBearerToken
): access token, token type, expirationError
(SafError
)
2. SAF API Interactions (ISafApiService
)
All API responses have the following structure:
IsSuccess
Data
Error
Retrieve Receivers
Task<SafReceiversResponse> GetReceiversAsync(SafReceiversRequest request);
- Response:
SafReceiversResponse
IsSuccess
Data
(IEnumerable<SafReceiver>
)Error
(SafError
)
Retrieve Member Public Key
Task<SafMemberPublicKeyResponse> GetMemberPublicKey(string bearerToken, string idpNumber);
- Response:
SafMemberPublicKeyResponse
IsSuccess
Data
(SafMemberPublicKey
)Error
(SafError
)
Upload Member Public Key
To generate public or private key you can use the method GenerateRsaKey of KmsHelper class
Task<SafMemberPublicKeyResponse> UploadMemberPublicKey(SafMemberPublicKeyUploadRequest request);
- Response:
SafMemberPublicKeyResponse
IsSuccess
Data
(SafMemberPublicKey
)Error
(SafError
)
Retrieve Member's Encrypted Public Key
Task<SafMemberGetEncryptedKeyResponse> GetMemberEncryptedPublicKey(string bearerToken, string keyId);
- Response:
SafMemberGetEncryptedKeyResponse
IsSuccess
Data
(SafMemberGetEncryptedKey
)Error
(SafError
)
Verify Member Decrypted Public Key
Task<SafMemberVerifyDecryptedKeyResponse> VerifyMemberDecryptedPublicKey(SafMemberVerifyDecryptedKeyRequest request);
- Response:
SafMemberVerifyDecryptedKeyResponse
IsSuccess
Data
(SafMemberVerifyDecryptedKey
)Error
(SafError
)
Activate Member Public Key
Task<SafDynamicResponse> ActivateMemberPublicKey(string bearerToken, string keyId);
- Response:
SafDynamicResponse
IsSuccess
Data
(dynamic
)Error
(SafError
)
3. SAF Event Handling
All event handler responses have the following structure:
IsSuccess
Data
Error
REST Proxy Event Handling (ISafRestProxyEventHandler
)
Send Offer NLPI Event
Task<SafSendOfferNlpiEventResponse> SendOfferNlpiEventAsync(SafSendOfferNlpiEventRequest request);
- Response:
SafSendOfferNlpiEventResponse
IsSuccess
Data
(SafSendOfferNlpiEvent
)Error
(SafError
)
- Response:
Receive Offer NLPI Event
Task<SafReceiveOfferNlpiEventResponse> ReceiveOfferNlpiEventAsync(SafReceiveOfferNlpiEventRequest request);
- Response:
SafReceiveOfferNlpiEventResponse
IsSuccess
Data
(IEnumerable<SafOfferNlpiEvent>
)Error
(SafError
)
- Response:
Kafka Event Handling (ISafKafkaEventHandler
)
Produce Event
Task<SafProduceEventResponse> ProduceEventAsync(SafProduceKafkaEventRequest request);
- Response:
SafProduceEventResponse
IsSuccess
Data
(bool
)Error
(SafError
)
- Response:
Consume Event
SafConsumeEventResponse ConsumeEvent(SafConsumeKafkaEventRequest request);
- Response:
SafConsumeEventResponse
IsSuccess
Data
(SafOfferNlpiEvent
)Error
(SafError
)
- Response:
Generate Public and Private Key
Generates an RSA key in PEM format for the specified key type and size.
Dictionary<RsaKeyType, string> GenerateRsaKey(RsaKeyType keyType, int keySize = 2048)
Parameters:
keyType
: The type of RSA key to generate. UseRsaKeyType.Public
for a public key,RsaKeyType.Private
for a private key, orRsaKeyType.Both
to generate both.keySize
: The size of the RSA key in bits. Default is 2048.
Returns:
A dictionary containing the generated key(s) as PEM-formatted strings, keyed byRsaKeyType
.
For example, the dictionary will contain entries forRsaKeyType.Public
and/orRsaKeyType.Private
.Remarks:
The returned PEM strings can be used for cryptographic operations such as encryption, decryption, signing, and verification.
Example:
var keys = KmsHelper.GenerateRsaKey(RsaKeyType.Both);
string publicKeyPem = keys[RsaKeyType.Public];
string privateKeyPem = keys[RsaKeyType.Private];
Response Structure
All responses in this library follow a consistent structure:
public class SafBaseResponse<T>
{
public bool IsSuccess { get; set; }
public T? Data { get; set; }
public SafError? Error { get; set; }
}
- IsSuccess:
true
if the operation succeeded, otherwisefalse
. - Data: The result data of type
T
. This is only populated ifIsSuccess
istrue
. - Error: An object of type
SafError
containing error details if the operation failed.
Always check IsSuccess
before using Data
. If IsSuccess
is false
, check Error
for details.
Error Handling
All errors are returned in the Error
property of the response, which is of type SafError
:
public class SafError
{
public string ErrorCode { get; set; }
public string ErrorMessage { get; set; }
public string ErrorMessageId { get; set; }
}
ErrorCode
: A machine-readable error code.ErrorMessage
: A human-readable error message.ErrorMessageId
: An optional error message identifier.
Dependencies
The following dependencies are required and are included in the NuGet package:
- .NET 8.0 or later
- Confluent.Kafka
- Confluent.SchemaRegistry
- Confluent.SchemaRegistry.Serdes.Json
- Microsoft.Extensions.DependencyInjection.Abstractions
- Microsoft.Extensions.Http
- Newtonsoft.Json
- System.Text.Json
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Confluent.Kafka (>= 2.3.0)
- Confluent.SchemaRegistry (>= 2.3.0)
- Confluent.SchemaRegistry.Serdes.Json (>= 2.3.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Http (>= 9.0.4)
- Newtonsoft.Json (>= 13.0.3)
- System.Text.Json (>= 9.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-beta.6 | 69 | 5/25/2025 |
1.0.0-beta.5 | 46 | 5/24/2025 |
1.0.0-beta.4 | 115 | 5/7/2025 |
1.0.0-beta.3 | 116 | 5/7/2025 |
1.0.0-beta.2 | 126 | 4/23/2025 |
1.0.0-beta.1 | 125 | 4/21/2025 |
0.0.0-preview.3 | 53 | 4/19/2025 |
0.0.0-preview.2 | 128 | 4/9/2025 |
0.0.0-preview.1 | 322 | 3/22/2025 |