smart-id-ruby-client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +14 -0
- data/CHANGELOG.md +13 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +436 -0
- data/Rakefile +12 -0
- data/lib/smart-id-ruby-client.rb +3 -0
- data/lib/smart_id_ruby/callback_url.rb +18 -0
- data/lib/smart_id_ruby/callback_url_util.rb +54 -0
- data/lib/smart_id_ruby/client.rb +124 -0
- data/lib/smart_id_ruby/configuration.rb +184 -0
- data/lib/smart_id_ruby/device_link_builder.rb +301 -0
- data/lib/smart_id_ruby/device_link_interaction.rb +67 -0
- data/lib/smart_id_ruby/errors/certificate_level_mismatch_error.rb +8 -0
- data/lib/smart_id_ruby/errors/document_unusable_error.rb +12 -0
- data/lib/smart_id_ruby/errors/error.rb +8 -0
- data/lib/smart_id_ruby/errors/expected_linked_session_error.rb +15 -0
- data/lib/smart_id_ruby/errors/no_suitable_account_of_requested_type_found_error.rb +10 -0
- data/lib/smart_id_ruby/errors/person_should_view_smart_id_portal_error.rb +8 -0
- data/lib/smart_id_ruby/errors/protocol_failure_error.rb +13 -0
- data/lib/smart_id_ruby/errors/relying_party_account_configuration_error.rb +10 -0
- data/lib/smart_id_ruby/errors/request_setup_error.rb +10 -0
- data/lib/smart_id_ruby/errors/request_validation_error.rb +8 -0
- data/lib/smart_id_ruby/errors/required_interaction_not_supported_by_app_error.rb +13 -0
- data/lib/smart_id_ruby/errors/response_error.rb +8 -0
- data/lib/smart_id_ruby/errors/server_maintenance_error.rb +8 -0
- data/lib/smart_id_ruby/errors/session_end_result_error.rb +15 -0
- data/lib/smart_id_ruby/errors/session_not_complete_error.rb +8 -0
- data/lib/smart_id_ruby/errors/session_not_found_error.rb +8 -0
- data/lib/smart_id_ruby/errors/session_secret_mismatch_error.rb +8 -0
- data/lib/smart_id_ruby/errors/session_timeout_error.rb +12 -0
- data/lib/smart_id_ruby/errors/smart_id_server_error.rb +12 -0
- data/lib/smart_id_ruby/errors/unprocessable_response_error.rb +9 -0
- data/lib/smart_id_ruby/errors/unsupported_client_api_version_error.rb +8 -0
- data/lib/smart_id_ruby/errors/user_account_not_found_error.rb +8 -0
- data/lib/smart_id_ruby/errors/user_account_unusable_error.rb +12 -0
- data/lib/smart_id_ruby/errors/user_refused_cert_choice_error.rb +14 -0
- data/lib/smart_id_ruby/errors/user_refused_confirmation_message_error.rb +13 -0
- data/lib/smart_id_ruby/errors/user_refused_confirmation_message_with_verification_choice_error.rb +13 -0
- data/lib/smart_id_ruby/errors/user_refused_display_text_and_pin_error.rb +13 -0
- data/lib/smart_id_ruby/errors/user_refused_error.rb +12 -0
- data/lib/smart_id_ruby/errors/user_selected_wrong_verification_code_error.rb +13 -0
- data/lib/smart_id_ruby/errors.rb +31 -0
- data/lib/smart_id_ruby/flows/base_builder.rb +90 -0
- data/lib/smart_id_ruby/flows/certificate_by_document_number_request_builder.rb +130 -0
- data/lib/smart_id_ruby/flows/device_link_authentication_session_request_builder.rb +208 -0
- data/lib/smart_id_ruby/flows/device_link_certificate_choice_session_request_builder.rb +112 -0
- data/lib/smart_id_ruby/flows/device_link_signature_session_request_builder.rb +286 -0
- data/lib/smart_id_ruby/flows/linked_notification_signature_session_request_builder.rb +235 -0
- data/lib/smart_id_ruby/flows/notification_authentication_session_request_builder.rb +184 -0
- data/lib/smart_id_ruby/flows/notification_certificate_choice_session_request_builder.rb +96 -0
- data/lib/smart_id_ruby/flows/notification_signature_session_request_builder.rb +272 -0
- data/lib/smart_id_ruby/models/authentication_identity.rb +19 -0
- data/lib/smart_id_ruby/models/authentication_response.rb +38 -0
- data/lib/smart_id_ruby/models/certificate_choice_response.rb +19 -0
- data/lib/smart_id_ruby/models/device_link_session_response.rb +34 -0
- data/lib/smart_id_ruby/models/notification_authentication_session_response.rb +25 -0
- data/lib/smart_id_ruby/models/notification_certificate_choice_session_response.rb +25 -0
- data/lib/smart_id_ruby/models/notification_signature_session_response.rb +29 -0
- data/lib/smart_id_ruby/models/session_status.rb +261 -0
- data/lib/smart_id_ruby/models/signature_response.rb +38 -0
- data/lib/smart_id_ruby/notification_interaction.rb +70 -0
- data/lib/smart_id_ruby/qr_code_generator.rb +65 -0
- data/lib/smart_id_ruby/rest/connector.rb +364 -0
- data/lib/smart_id_ruby/rest/session_status_poller.rb +125 -0
- data/lib/smart_id_ruby/rp_challenge.rb +37 -0
- data/lib/smart_id_ruby/rp_challenge_generator.rb +28 -0
- data/lib/smart_id_ruby/semantics_identifier.rb +35 -0
- data/lib/smart_id_ruby/validation/authentication_certificate_validator.rb +90 -0
- data/lib/smart_id_ruby/validation/authentication_identity_mapper.rb +227 -0
- data/lib/smart_id_ruby/validation/base_authentication_response_validator.rb +304 -0
- data/lib/smart_id_ruby/validation/certificate_choice_response_validator.rb +104 -0
- data/lib/smart_id_ruby/validation/certificate_validator.rb +170 -0
- data/lib/smart_id_ruby/validation/device_link_authentication_response_validator.rb +76 -0
- data/lib/smart_id_ruby/validation/error_result_handler.rb +88 -0
- data/lib/smart_id_ruby/validation/notification_authentication_response_validator.rb +16 -0
- data/lib/smart_id_ruby/validation/signature_payload_builder.rb +62 -0
- data/lib/smart_id_ruby/validation/signature_response_validator.rb +345 -0
- data/lib/smart_id_ruby/validation/signature_value_validator.rb +76 -0
- data/lib/smart_id_ruby/validation/trusted_ca_cert_store.rb +20 -0
- data/lib/smart_id_ruby/verification_code_calculator.rb +31 -0
- data/lib/smart_id_ruby/version.rb +5 -0
- data/lib/smart_id_ruby.rb +76 -0
- metadata +173 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b91db6fa6f6c9adfc7ba1bc61e178f26b203d3a87517986ebb7528810fa4b506
|
|
4
|
+
data.tar.gz: 13f4360d2baf919d80c2d471383a914befc0bc25faddddfd713dee5c9b14c215
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 28df6c16e3c0d265de6f09f7b438e1b506dbbd03de0bfbd342a0516c1569019c640fe00a675ecb29515d3d5570984f67e9c929ad2f47c17568f390bf89495c3d
|
|
7
|
+
data.tar.gz: f9225bed6e6cfdf290fa1da005a62a158c06667afe787f21cee437a17d370e9d13ed1ad1e09a8008b9840a0074c256213127abea6bc1589b383cc4c7ef4df9cb
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 3.0
|
|
3
|
+
|
|
4
|
+
Style/StringLiterals:
|
|
5
|
+
EnforcedStyle: double_quotes
|
|
6
|
+
|
|
7
|
+
Style/StringLiteralsInInterpolation:
|
|
8
|
+
EnforcedStyle: double_quotes
|
|
9
|
+
|
|
10
|
+
Metrics/ParameterLists:
|
|
11
|
+
Max: 6
|
|
12
|
+
|
|
13
|
+
Layout/MultilineMethodCallIndentation:
|
|
14
|
+
EnforcedStyle: indented
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
## [Unreleased]
|
|
2
|
+
|
|
3
|
+
- Implemented trust-chain certificate validation parity with `TrustedCaCertStore` and `CertificateValidator`, and wired chain validation into signature/certificate-choice/authentication certificate validation flows.
|
|
4
|
+
- Added `AuthenticationIdentity`, `SignatureResponse`, and `CertificateChoiceResponse` models for validator outputs and added `CertificateLevelMismatchError`.
|
|
5
|
+
- Added `AuthenticationIdentityMapper` parity behavior to map identity fields from certificate subject and derive date-of-birth with certificate-attribute-first + national-identity fallback logic.
|
|
6
|
+
- Added focused specs for notification authentication/signature builders and client factory wiring.
|
|
7
|
+
- Added focused specs for certificate-by-document-number builder and client factory wiring.
|
|
8
|
+
- Added focused validator specs for notification-authentication, signature, and certificate-choice response validation flows.
|
|
9
|
+
- Added runtime dependency on `base64` to avoid Ruby 3.4 default-gem warnings.
|
|
10
|
+
|
|
11
|
+
## [0.1.0] - 2026-02-17
|
|
12
|
+
|
|
13
|
+
- Initial release
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
[INSERT CONTACT METHOD].
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sergei Tsõganov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
[](https://github.com/maricavor/smart-id-ruby-client/actions/workflows/main.yml)
|
|
2
|
+
[](https://codecov.io/github/maricavor/smart-id-ruby-client)
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
|
|
5
|
+
# smart-id-ruby-client
|
|
6
|
+
|
|
7
|
+
Ruby client gem for integrating [Smart-ID RP API v3.1](https://sk-eid.github.io/smart-id-documentation/index.html) into Ruby applications.
|
|
8
|
+
|
|
9
|
+
This gem follows the same high-level flow model as the Smart-ID Java client:
|
|
10
|
+
|
|
11
|
+
- start session (authentication / certificate choice / signature)
|
|
12
|
+
- poll session status
|
|
13
|
+
- validate final session response
|
|
14
|
+
|
|
15
|
+
## Table of contents
|
|
16
|
+
|
|
17
|
+
- [Requirements](#requirements)
|
|
18
|
+
- [Installation](#installation)
|
|
19
|
+
- [Quick setup](#quick-setup)
|
|
20
|
+
- [Logging](#logging)
|
|
21
|
+
- [Interactions](#interactions)
|
|
22
|
+
- [Flows](#flows)
|
|
23
|
+
- [Notification authentication](#notification-authentication)
|
|
24
|
+
- [Device-link authentication](#device-link-authentication)
|
|
25
|
+
- [Notification signature](#notification-signature)
|
|
26
|
+
- [Device-link signature](#device-link-signature)
|
|
27
|
+
- [Certificate by document number](#certificate-by-document-number)
|
|
28
|
+
- [Device-link certificate choice + linked notification signature](#device-link-certificate-choice--linked-notification-signature)
|
|
29
|
+
- [Notification certificate choice](#notification-certificate-choice)
|
|
30
|
+
- [Generating device link and QR-code](#generating-device-link-and-qr-code)
|
|
31
|
+
- [Session status polling](#session-status-polling)
|
|
32
|
+
- [Response validation](#response-validation)
|
|
33
|
+
- [Network and SSL configuration](#network-and-ssl-configuration)
|
|
34
|
+
- [Exception handling](#exception-handling)
|
|
35
|
+
- [Development](#development)
|
|
36
|
+
- [License](#license)
|
|
37
|
+
|
|
38
|
+
## Requirements
|
|
39
|
+
|
|
40
|
+
- Ruby `>= 3.0`
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
Add to your app:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
bundle add smart-id-ruby-client
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or install directly:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
gem install smart-id-ruby-client
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Quick setup
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
require "smart-id-ruby-client" # or: require "smart_id_ruby"
|
|
60
|
+
require "base64"
|
|
61
|
+
require "securerandom"
|
|
62
|
+
|
|
63
|
+
SmartIdRuby.configure do |config|
|
|
64
|
+
config.relying_party_uuid = ENV.fetch("SMART_ID_RP_UUID")
|
|
65
|
+
config.relying_party_name = ENV.fetch("SMART_ID_RP_NAME")
|
|
66
|
+
config.host_url = ENV.fetch("SMART_ID_HOST_URL") # e.g. https://sid.demo.sk.ee/smart-id-rp/v3/
|
|
67
|
+
config.default_certificate_level = "QUALIFIED" # optional app-level default
|
|
68
|
+
config.poller_timeout_seconds = 10 # optional
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
client = SmartIdRuby.client
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Logging
|
|
75
|
+
|
|
76
|
+
The library uses `SmartIdRuby.logger` for connector-level logs.
|
|
77
|
+
Default level is `WARN`.
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
require "logger"
|
|
81
|
+
require "smart-id-ruby-client" # or: require "smart_id_ruby"
|
|
82
|
+
|
|
83
|
+
SmartIdRuby.logger = Logger.new($stdout)
|
|
84
|
+
SmartIdRuby.logger.level = Logger::DEBUG
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
At `DEBUG`, logs include method, URL, and status code.
|
|
88
|
+
Request and response bodies are not logged by default.
|
|
89
|
+
|
|
90
|
+
## Interactions
|
|
91
|
+
|
|
92
|
+
You can pass interactions either as hashes or helper objects.
|
|
93
|
+
|
|
94
|
+
### Hash style
|
|
95
|
+
|
|
96
|
+
```ruby
|
|
97
|
+
[
|
|
98
|
+
{ type: "displayTextAndPIN", displayText60: "Log in" },
|
|
99
|
+
{ type: "confirmationMessage", displayText200: "Confirm login" }
|
|
100
|
+
]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Helper style (`NotificationInteraction`)
|
|
104
|
+
|
|
105
|
+
```ruby
|
|
106
|
+
[
|
|
107
|
+
SmartIdRuby::NotificationInteraction.confirmationMessageAndVerificationCodeChoice("Confirm login"),
|
|
108
|
+
SmartIdRuby::NotificationInteraction.confirmationMessage("Confirm login fallback"),
|
|
109
|
+
SmartIdRuby::NotificationInteraction.displayTextAndPin("Log in fallback")
|
|
110
|
+
]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Ruby-style aliases are also available:
|
|
114
|
+
|
|
115
|
+
- `display_text_and_pin`
|
|
116
|
+
- `confirmation_message`
|
|
117
|
+
- `confirmation_message_and_verification_code_choice`
|
|
118
|
+
|
|
119
|
+
## Flows
|
|
120
|
+
|
|
121
|
+
### Notification authentication
|
|
122
|
+
|
|
123
|
+
```ruby
|
|
124
|
+
rp_challenge = Base64.strict_encode64(SecureRandom.random_bytes(32))
|
|
125
|
+
|
|
126
|
+
auth_builder = client.create_notification_authentication
|
|
127
|
+
.with_document_number("PNOEE-30303039914") # or .with_semantics_identifier("PNOEE-...")
|
|
128
|
+
.with_certificate_level("QUALIFIED")
|
|
129
|
+
.with_rp_challenge(rp_challenge)
|
|
130
|
+
.with_interactions([
|
|
131
|
+
SmartIdRuby::NotificationInteraction.displayTextAndPin("Log in")
|
|
132
|
+
])
|
|
133
|
+
.with_share_md_client_ip_address(true) # optional
|
|
134
|
+
|
|
135
|
+
auth_init = auth_builder.init_authentication_session
|
|
136
|
+
session_id = auth_init["sessionID"] || auth_init[:sessionID]
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Device-link authentication
|
|
140
|
+
|
|
141
|
+
```ruby
|
|
142
|
+
rp_challenge = Base64.strict_encode64(SecureRandom.random_bytes(32))
|
|
143
|
+
|
|
144
|
+
builder = client.create_device_link_authentication
|
|
145
|
+
.with_rp_challenge(rp_challenge)
|
|
146
|
+
.with_interactions([
|
|
147
|
+
SmartIdRuby::NotificationInteraction.confirmationMessage("Log in to MyApp")
|
|
148
|
+
])
|
|
149
|
+
.with_initial_callback_url("https://example.com/callback") # optional
|
|
150
|
+
|
|
151
|
+
# Anonymous device-link auth (no identifier)
|
|
152
|
+
init = builder.init_authentication_session
|
|
153
|
+
|
|
154
|
+
# Identified flow variants:
|
|
155
|
+
# builder.with_document_number("PNOLT-40504040001-MOCK-Q")
|
|
156
|
+
# builder.with_semantics_identifier("PNOEE-30303039914")
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Notification signature
|
|
160
|
+
|
|
161
|
+
```ruby
|
|
162
|
+
sig_builder = client.create_notification_signature
|
|
163
|
+
.with_semantics_identifier("PNOEE-30303039914") # or .with_document_number(...)
|
|
164
|
+
.with_certificate_level("QUALIFIED")
|
|
165
|
+
.with_signable_data("data to sign")
|
|
166
|
+
.with_interactions([
|
|
167
|
+
SmartIdRuby::NotificationInteraction.displayTextAndPin("Please sign")
|
|
168
|
+
])
|
|
169
|
+
.with_nonce(SecureRandom.hex(8)) # optional
|
|
170
|
+
|
|
171
|
+
sig_init = sig_builder.init_signature_session
|
|
172
|
+
session_id = sig_init["sessionID"] || sig_init[:sessionID]
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
You can use `with_signable_hash(...)` instead of `with_signable_data(...)`.
|
|
176
|
+
|
|
177
|
+
### Device-link signature
|
|
178
|
+
|
|
179
|
+
```ruby
|
|
180
|
+
sig_builder = client.create_device_link_signature
|
|
181
|
+
.with_document_number("PNOLT-40504040001-MOCK-Q") # or .with_semantics_identifier(...)
|
|
182
|
+
.with_certificate_level("QUALIFIED")
|
|
183
|
+
.with_signable_data("data to sign")
|
|
184
|
+
.with_interactions([
|
|
185
|
+
SmartIdRuby::NotificationInteraction.confirmationMessage("Please sign document")
|
|
186
|
+
])
|
|
187
|
+
.with_initial_callback_url("https://example.com/callback") # optional
|
|
188
|
+
|
|
189
|
+
sig_init = sig_builder.init_signature_session
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Certificate by document number
|
|
193
|
+
|
|
194
|
+
```ruby
|
|
195
|
+
result = client.create_certificate_by_document_number
|
|
196
|
+
.with_document_number("PNOLT-40504040001-MOCK-Q")
|
|
197
|
+
.with_certificate_level("QUALIFIED")
|
|
198
|
+
.get_certificate_by_document_number
|
|
199
|
+
|
|
200
|
+
certificate_level = result[:certificate_level]
|
|
201
|
+
certificate = result[:certificate] # OpenSSL::X509::Certificate
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Device-link certificate choice + linked notification signature
|
|
205
|
+
|
|
206
|
+
```ruby
|
|
207
|
+
cert_choice_init = client.create_device_link_certificate_request
|
|
208
|
+
.with_certificate_level("QUALIFIED")
|
|
209
|
+
.with_nonce(SecureRandom.hex(8))
|
|
210
|
+
.init_certificate_choice
|
|
211
|
+
|
|
212
|
+
cert_choice_session_id = cert_choice_init["sessionID"] || cert_choice_init[:sessionID]
|
|
213
|
+
|
|
214
|
+
cert_choice_status = client.session_status_poller.fetch_final_session_status(cert_choice_session_id)
|
|
215
|
+
|
|
216
|
+
cert_choice_response = SmartIdRuby::Validation::CertificateChoiceResponseValidator.new
|
|
217
|
+
.validate(cert_choice_status, "QUALIFIED")
|
|
218
|
+
|
|
219
|
+
linked_sig_init = client.create_linked_notification_signature
|
|
220
|
+
.with_document_number(cert_choice_response.document_number)
|
|
221
|
+
.with_linked_session_id(cert_choice_session_id)
|
|
222
|
+
.with_signable_data("data to sign")
|
|
223
|
+
.with_interactions([
|
|
224
|
+
SmartIdRuby::NotificationInteraction.displayTextAndPin("Please sign")
|
|
225
|
+
])
|
|
226
|
+
.init_signature_session
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Notification certificate choice
|
|
230
|
+
|
|
231
|
+
```ruby
|
|
232
|
+
init = client.create_notification_certificate_choice
|
|
233
|
+
.with_semantics_identifier("PNOEE-30303039914")
|
|
234
|
+
.with_certificate_level("QUALIFIED")
|
|
235
|
+
.with_nonce(SecureRandom.hex(8))
|
|
236
|
+
.init_certificate_choice
|
|
237
|
+
|
|
238
|
+
session_id = init["sessionID"] || init[:sessionID]
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Generating device link and QR-code
|
|
242
|
+
|
|
243
|
+
After starting a device-link flow (authentication, signature, or certificate choice),
|
|
244
|
+
you can create a signed device-link URI and QR image.
|
|
245
|
+
|
|
246
|
+
```ruby
|
|
247
|
+
# Example: after device-link authentication init
|
|
248
|
+
auth_builder = client.create_device_link_authentication
|
|
249
|
+
.with_rp_challenge(Base64.strict_encode64(SecureRandom.random_bytes(32)))
|
|
250
|
+
.with_interactions([SmartIdRuby::NotificationInteraction.displayTextAndPin("Log in")])
|
|
251
|
+
.with_document_number("PNOLT-40504040001-MOCK-Q")
|
|
252
|
+
|
|
253
|
+
init = auth_builder.init_authentication_session
|
|
254
|
+
|
|
255
|
+
session_token = init["sessionToken"] || init[:sessionToken]
|
|
256
|
+
session_secret = init["sessionSecret"] || init[:sessionSecret]
|
|
257
|
+
device_link_base = init["deviceLinkBase"] || init[:deviceLinkBase]
|
|
258
|
+
request = auth_builder.get_authentication_session_request
|
|
259
|
+
request_interactions = request[:interactions]
|
|
260
|
+
request_digest = request.dig(:signatureProtocolParameters, :rpChallenge)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Build unprotected and protected device-link:
|
|
264
|
+
|
|
265
|
+
```ruby
|
|
266
|
+
dynamic = client.create_dynamic_content
|
|
267
|
+
.with_device_link_base(device_link_base)
|
|
268
|
+
.with_session_type(SmartIdRuby::SessionType::AUTHENTICATION)
|
|
269
|
+
.with_device_link_type(SmartIdRuby::DeviceLinkType::QR_CODE)
|
|
270
|
+
.with_session_token(session_token)
|
|
271
|
+
.with_elapsed_seconds(1)
|
|
272
|
+
.with_lang("eng")
|
|
273
|
+
.with_digest(request_digest)
|
|
274
|
+
.with_interactions(request_interactions)
|
|
275
|
+
|
|
276
|
+
unprotected_uri = dynamic.create_unprotected_uri
|
|
277
|
+
device_link_uri = dynamic.build_device_link(session_secret)
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Generate QR-code (PNG Data URI by default):
|
|
281
|
+
|
|
282
|
+
```ruby
|
|
283
|
+
qr_data_uri = SmartIdRuby::QrCodeGenerator.generate_data_uri(device_link_uri.to_s)
|
|
284
|
+
|
|
285
|
+
# or create image object and convert manually
|
|
286
|
+
image = SmartIdRuby::QrCodeGenerator.generate_image(device_link_uri.to_s, 610, 610, 4)
|
|
287
|
+
qr_data_uri = SmartIdRuby::QrCodeGenerator.convert_to_data_uri(image, "png")
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Session status polling
|
|
291
|
+
|
|
292
|
+
Use `SessionStatusPoller` for both one-shot and final-status polling.
|
|
293
|
+
|
|
294
|
+
```ruby
|
|
295
|
+
poller = client.session_status_poller
|
|
296
|
+
|
|
297
|
+
# Query once
|
|
298
|
+
status = poller.get_session_status(session_id)
|
|
299
|
+
|
|
300
|
+
# Poll until COMPLETE
|
|
301
|
+
final_status = poller.fetch_final_session_status(session_id)
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Tune polling behavior:
|
|
305
|
+
|
|
306
|
+
```ruby
|
|
307
|
+
client.set_session_status_response_socket_open_time(:seconds, 5) # timeoutMs for each status request
|
|
308
|
+
client.set_polling_sleep_timeout(:seconds, 1) # sleep between polls
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Supported time units are `:milliseconds`, `:seconds`, `:minutes`, `:hours`.
|
|
312
|
+
|
|
313
|
+
## Response validation
|
|
314
|
+
|
|
315
|
+
Builders validate request/initialization responses.
|
|
316
|
+
For final session status payloads, use validators:
|
|
317
|
+
|
|
318
|
+
### Notification authentication response validator
|
|
319
|
+
|
|
320
|
+
```ruby
|
|
321
|
+
identity = SmartIdRuby::Validation::NotificationAuthenticationResponseValidator.new
|
|
322
|
+
.validate(
|
|
323
|
+
final_status,
|
|
324
|
+
auth_builder.get_authentication_session_request,
|
|
325
|
+
"SMART_ID", # schema_name
|
|
326
|
+
nil # brokered_rp_name (optional)
|
|
327
|
+
)
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Device-link authentication response validator
|
|
331
|
+
|
|
332
|
+
```ruby
|
|
333
|
+
response = SmartIdRuby::Validation::DeviceLinkAuthenticationResponseValidator.new.validate(
|
|
334
|
+
final_status,
|
|
335
|
+
auth_builder.get_authentication_session_request,
|
|
336
|
+
nil, # user_challenge_verifier (required for Web2App/App2App)
|
|
337
|
+
"SMART_ID", # schema_name
|
|
338
|
+
nil # brokered_rp_name
|
|
339
|
+
)
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Signature response validator
|
|
343
|
+
|
|
344
|
+
```ruby
|
|
345
|
+
signature = SmartIdRuby::Validation::SignatureResponseValidator.new
|
|
346
|
+
.validate(final_status, "QUALIFIED")
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Certificate choice response validator
|
|
350
|
+
|
|
351
|
+
```ruby
|
|
352
|
+
choice = SmartIdRuby::Validation::CertificateChoiceResponseValidator.new
|
|
353
|
+
.validate(final_status, "QUALIFIED")
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## Network and SSL configuration
|
|
357
|
+
|
|
358
|
+
### Faraday request options
|
|
359
|
+
|
|
360
|
+
```ruby
|
|
361
|
+
client.network_connection_config = {
|
|
362
|
+
open_timeout: 5,
|
|
363
|
+
timeout: 30,
|
|
364
|
+
headers: { "X-Request-ID" => "123" }
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
You can also nest options under `:request`:
|
|
369
|
+
|
|
370
|
+
```ruby
|
|
371
|
+
client.network_connection_config = {
|
|
372
|
+
request: {
|
|
373
|
+
open_timeout: 5,
|
|
374
|
+
timeout: 30
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### Custom Faraday connection
|
|
380
|
+
|
|
381
|
+
```ruby
|
|
382
|
+
client.configured_connection = Faraday.new(url: client.host_url) do |f|
|
|
383
|
+
f.adapter Faraday.default_adapter
|
|
384
|
+
end
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### Trusting custom CA certificates
|
|
388
|
+
|
|
389
|
+
```ruby
|
|
390
|
+
cert_store = OpenSSL::X509::Store.new
|
|
391
|
+
cert_store.set_default_paths
|
|
392
|
+
# cert_store.add_cert(OpenSSL::X509::Certificate.new(File.read("ca.pem")))
|
|
393
|
+
|
|
394
|
+
ssl_context = OpenSSL::SSL::SSLContext.new
|
|
395
|
+
ssl_context.cert_store = cert_store
|
|
396
|
+
|
|
397
|
+
client.trust_ssl_context = ssl_context
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
## Exception handling
|
|
401
|
+
|
|
402
|
+
Main exception classes:
|
|
403
|
+
|
|
404
|
+
- `SmartIdRuby::Errors::RequestSetupError`
|
|
405
|
+
- `SmartIdRuby::Errors::RequestValidationError`
|
|
406
|
+
- `SmartIdRuby::Errors::UnprocessableResponseError`
|
|
407
|
+
- `SmartIdRuby::Errors::SessionEndResultError`
|
|
408
|
+
- `SmartIdRuby::Errors::SessionNotCompleteError`
|
|
409
|
+
- `SmartIdRuby::Errors::CertificateLevelMismatchError`
|
|
410
|
+
- `SmartIdRuby::Errors::DocumentUnusableError`
|
|
411
|
+
- `SmartIdRuby::Errors::UserRefusedDisplayTextAndPinError`
|
|
412
|
+
- `SmartIdRuby::Errors::UserRefusedConfirmationMessageError`
|
|
413
|
+
- `SmartIdRuby::Errors::UserRefusedConfirmationMessageWithVerificationChoiceError`
|
|
414
|
+
|
|
415
|
+
Connector/network-related classes:
|
|
416
|
+
|
|
417
|
+
- `SmartIdRuby::Errors::SessionNotFoundError`
|
|
418
|
+
- `SmartIdRuby::Errors::UserAccountNotFoundError`
|
|
419
|
+
- `SmartIdRuby::Errors::RelyingPartyAccountConfigurationError`
|
|
420
|
+
- `SmartIdRuby::Errors::NoSuitableAccountOfRequestedTypeFoundError`
|
|
421
|
+
- `SmartIdRuby::Errors::PersonShouldViewSmartIdPortalError`
|
|
422
|
+
- `SmartIdRuby::Errors::UnsupportedClientApiVersionError`
|
|
423
|
+
- `SmartIdRuby::Errors::ServerMaintenanceError`
|
|
424
|
+
|
|
425
|
+
## Development
|
|
426
|
+
|
|
427
|
+
After checking out the repo:
|
|
428
|
+
|
|
429
|
+
```bash
|
|
430
|
+
bin/setup
|
|
431
|
+
bundle exec rake
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
## License
|
|
435
|
+
|
|
436
|
+
The gem is available as open source under the terms of the MIT License.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SmartIdRuby
|
|
4
|
+
# Represents a Smart-ID callback URL and its associated one-time token
|
|
5
|
+
# generated by the Smart-ID service for Web2App/device-link flows.
|
|
6
|
+
class CallbackUrl
|
|
7
|
+
attr_reader :url, :token
|
|
8
|
+
|
|
9
|
+
def initialize(url:, token:)
|
|
10
|
+
@url = url
|
|
11
|
+
@token = token
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_s
|
|
15
|
+
url
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|