Module: Ksef::Auth

Defined in:
lib/ksef/auth.rb,
lib/ksef/auth/token.rb,
lib/ksef/auth/xades.rb,
lib/ksef/auth/client.rb,
lib/ksef/auth/signer.rb,
lib/ksef/auth/status.rb,
lib/ksef/auth/tokens.rb,
lib/ksef/auth/challenge.rb,
lib/ksef/auth/validator.rb,
lib/ksef/auth/initiation.rb,
lib/ksef/auth/token_info.rb,
lib/ksef/auth/access_token.rb,
lib/ksef/auth/token_request.rb,
lib/ksef/auth/operation_status.rb,
lib/ksef/auth/signature_template.rb,
lib/ksef/auth/authorization_policy.rb

Overview

Authentication against KSeF (docs/REFERENCE.md §4).

Defined Under Namespace

Modules: Status, Validator, Xades Classes: AccessToken, AuthorizationPolicy, Challenge, Client, Initiation, OperationStatus, SignatureTemplate, Signer, Token, TokenInfo, TokenRequest, Tokens

Constant Summary collapse

NAMESPACES =

Both schema versions of the AuthTokenRequest document.

2.0 is the default, and that is a deliberate correction. v2.1 is the newer file, but every piece of available evidence points at 2.0 as what the API actually expects: both official clients bind to it ([XmlRoot(Namespace = "…/2.0")] in AuthenticationTokenRequest.cs; JAXB classes generated against 2.0 in ksef-client-java), the Java client bundles its own copy of the 2.0 schema, and every worked example in CIRFMF/ksef-api declares 2.0. Nothing observed so far emits 2.1. See §14.4.

{
  "2.0" => "http://ksef.mf.gov.pl/auth/token/2.0",
  "2.1" => "http://ksef.mf.gov.pl/auth/token/2.1"
}.freeze
DEFAULT_SCHEMA_VERSION =
"2.0"

Class Method Summary collapse

Class Method Details

.time(value) ⇒ Time?

Parses the contract's date-time fields.

Returns nil rather than raising on an unparseable value: these timestamps are informational — expiry hints, start times — and a malformed one is no reason to fail an authentication that otherwise succeeded. The fields that actually matter are the tokens themselves.

Returns:

  • (Time, nil)


33
34
35
36
37
38
39
40
# File 'lib/ksef/auth.rb', line 33

def time(value)
  return value if value.is_a?(Time)
  return nil if value.nil? || value.to_s.empty?

  Time.iso8601(value.to_s)
rescue ArgumentError
  nil
end