Relying party documentation

ASP.NET Core — document signing

Cookie or OpenID Connect session plus a typed HttpClient for multipart sign requests.

  • Complete SSO guide first (/developers/sso/dotnet)
  • EidDocumentSigning:ApiBaseUrl in configuration
  • Persist broker access token at sign-in (server-side)
  • Admin enabled esign_sign on the OidcClients row for your WSO2 client id
  • Call POST /api/rp/esign/documents/sign directly; do not disable upload until validate succeeds

Copy-paste steps for PAdES-T PDF signing via the eID API. Reference implementation: COCI Portal (EidDocumentSigningClient). After SSO, the backend posts the PDF to the sign API. Leave the upload enabled.

Step 1

appsettings / user secrets

Configure eID API URL and broker client id for X-Sso-Client-Id.

json
{
  "EidDocumentSigning": {
    "ApiBaseUrl": "https://sxm-eid-dev.eastus.cloudapp.azure.com",
    "BrokerClientId": "YOUR_WSO2_CLIENT_ID",
    "UseBrokerAccessToken": true,
    "TimeoutSeconds": 120
  }
}
Step 2

Options class

Typed configuration for dependency injection.

csharp
public sealed class EidDocumentSigningOptions
{
    public const string SectionName = "EidDocumentSigning";
    public string ApiBaseUrl { get; set; } = "";
    public string? BrokerClientId { get; set; }
    public bool UseBrokerAccessToken { get; set; } = true;
    public int TimeoutSeconds { get; set; } = 120;
}
Step 3

EidDocumentSigningClient

Server-side multipart POST. Pass the citizen broker access token from your OIDC session.

csharp
public sealed class EidDocumentSigningClient
{
    private readonly HttpClient _http;
    private readonly EidDocumentSigningOptions _options;

    public EidDocumentSigningClient(HttpClient http, IOptions<EidDocumentSigningOptions> options)
    {
        _http = http;
        _options = options.Value;
        _http.Timeout = TimeSpan.FromSeconds(_options.TimeoutSeconds);
    }

    public async Task<EidSignResult> SignPdfAsync(Stream pdf, string fileName, string accessToken, CancellationToken ct = default)
    {
        using var content = new MultipartFormDataContent();
        var streamContent = new StreamContent(pdf);
        streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
        content.Add(streamContent, "file", fileName);

        using var request = new HttpRequestMessage(HttpMethod.Post, $"{_options.ApiBaseUrl.TrimEnd('/')}/api/rp/esign/documents/sign")
        {
            Content = content,
        };
        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
        if (_options.UseBrokerAccessToken && !string.IsNullOrWhiteSpace(_options.BrokerClientId))
        {
            request.Headers.TryAddWithoutValidation("X-Sso-Client-Id", _options.BrokerClientId);
        }

        using var response = await _http.SendAsync(request, ct);
        return await ParseResponseAsync(response, ct);
    }

    private static async Task<EidSignResult> ParseResponseAsync(HttpResponseMessage response, CancellationToken ct)
    {
        var json = await response.Content.ReadAsStringAsync(ct);
        return response.IsSuccessStatusCode ? EidSignResult.Ok(json) : EidSignResult.Fail(response.StatusCode, json);
    }
}
Step 4

Program.cs registration

Named HttpClient with reasonable timeout.

csharp
builder.Services.Configure<EidDocumentSigningOptions>(
    builder.Configuration.GetSection(EidDocumentSigningOptions.SectionName));
builder.Services.AddHttpClient<EidDocumentSigningClient>();
Step 5

Controller action

Retrieve the access token saved at sign-in and return the signed PDF. Show API errors; leave the upload enabled.

csharp
[Authorize]
[HttpPost("documents/sign")]
public async Task<IActionResult> SignDocument(IFormFile file, CancellationToken ct)
{
    if (file is null || file.Length == 0)
        return BadRequest("PDF required.");

    var accessToken = await _tokenStore.GetAccessTokenAsync(User);
    if (string.IsNullOrWhiteSpace(accessToken))
        return Unauthorized();

    await using var stream = file.OpenReadStream();
    var result = await _signingClient.SignPdfAsync(stream, file.FileName, accessToken, ct);
    if (!result.Success)
        return StatusCode((int)result.StatusCode, result.ErrorBody);

    var signed = result.ParseSignedPdfBase64();
    if (signed is null)
        return StatusCode(502, "Invalid sign response.");

    return File(signed, "application/pdf", $"signed-{file.FileName}");
}
Step 6

Platform prerequisites

Request esign_sign on your eID OidcClients row (admin RP queue → Update OIDC policy). Citizen needs an issued eSignature certificate.

text
Admin: /admin/rp-applications → Approved app → add scope esign_sign + claim eid
Citizen: /citizen/signing → issue certificate
RP SSO: scope bundle must include eid (WSO2_SCOPE / approved scopes)
Step 7

Optional validate (curl)

Not required before sign. Same auth headers. Skipping it must not disable the PDF upload.

bash
curl -sS -X POST https://sxm-eid-dev.eastus.cloudapp.azure.com/api/rp/esign/documents/validate \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "X-Sso-Client-Id: YOUR_WSO2_CLIENT_ID" | jq
Step 8

Sign (curl)

Required call. X-Sso-Client-Id is your WSO2 client id, mapped to the OidcClients row with that same id.

bash
curl -sS -X POST https://sxm-eid-dev.eastus.cloudapp.azure.com/api/rp/esign/documents/sign \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "X-Sso-Client-Id: YOUR_WSO2_CLIENT_ID" \
  -F "file=@sample.pdf" | jq