viisp-auth-custom 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.
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VIISP
4
+ module Auth
5
+ module Requests
6
+ class Ticket
7
+ include Soap
8
+ include Signature
9
+
10
+ NODE_ID = 'uniqueNodeId'
11
+
12
+ def initialize(providers: nil, attributes: nil, user_information: nil, postback_url: nil,
13
+ custom_data: '')
14
+ @providers = providers || configuration.providers
15
+ @attributes = attributes || configuration.attributes
16
+ @user_information = user_information || configuration.user_information
17
+ @postback_url = postback_url || configuration.postback_url
18
+ @custom_data = custom_data
19
+ end
20
+
21
+ def build
22
+ builder = Nokogiri::XML::Builder.new do |builder|
23
+ soap_envelope(builder) do
24
+ build_request(builder)
25
+ end
26
+ end
27
+
28
+ builder.doc
29
+ end
30
+
31
+ private
32
+
33
+ def build_request(builder)
34
+ builder[:authentication].authenticationRequest(id: NODE_ID) do
35
+ builder.pid(configuration.pid)
36
+
37
+ @providers.each do |provider|
38
+ builder.authenticationProvider(provider)
39
+ end
40
+
41
+ @attributes.each do |attribute|
42
+ builder.authenticationAttribute(attribute)
43
+ end
44
+
45
+ @user_information.each do |val|
46
+ builder.userInformation(val)
47
+ end
48
+
49
+ builder.postbackUrl(@postback_url)
50
+ builder.customData(@custom_data)
51
+
52
+ build_signature(builder, NODE_ID)
53
+ end
54
+ end
55
+
56
+ def configuration
57
+ Auth.configuration
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'xmldsig'
4
+
5
+ module VIISP
6
+ module Auth
7
+ module Signing
8
+ SCHEMAS_PATH = File.expand_path('../../../../schemas', __FILE__).freeze
9
+
10
+ module_function
11
+
12
+ def sign(doc, private_key = Auth.configuration.private_key)
13
+ signed_document = Xmldsig::SignedDocument.new(doc, id_attr: 'id')
14
+ signed_document.sign(private_key)
15
+ end
16
+
17
+ def validate!(doc, certificate = Auth.configuration.service_cert)
18
+ Dir.chdir(SCHEMAS_PATH) do
19
+ schema = IO.read('authentication.xsd')
20
+ signed_document = Xmldsig::SignedDocument.new(doc, id_attr: 'id')
21
+ # signed_document.validate(certificate, schema) ||
22
+ # raise(SignatureError, 'Unable to verify signature')
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VIISP
4
+ module Auth
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
data/lib/viisp/auth.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'nokogiri'
2
+ require 'viisp/auth/version'
3
+ require 'viisp/auth/configuration'
4
+ require 'viisp/auth/errors'
5
+ require 'viisp/auth/client'
6
+ require 'viisp/auth/signing'
7
+ require 'viisp/auth/identity'
8
+ require 'viisp/auth/requests/soap'
9
+ require 'viisp/auth/requests/signature'
10
+ require 'viisp/auth/requests/ticket'
11
+ require 'viisp/auth/requests/identity'
12
+
13
+ module VIISP
14
+ module Auth
15
+ module_function
16
+
17
+ def configure
18
+ yield(configuration)
19
+ end
20
+
21
+ def configuration
22
+ @configuration ||= Configuration.new
23
+ end
24
+
25
+ def client
26
+ @client ||= Client.new
27
+ end
28
+
29
+ def portal_endpoint
30
+ configuration.portal_endpoint
31
+ end
32
+
33
+ def ticket(options = {})
34
+ request = Requests::Ticket.new(**options).build
35
+
36
+ doc = client.post(request)
37
+ doc.remove_namespaces!
38
+ doc.at('ticket')&.text
39
+ end
40
+
41
+ def identity(options = {})
42
+ request = Requests::Identity.new(**options).build
43
+
44
+ doc = client.post(request)
45
+ doc.remove_namespaces!
46
+
47
+ Identity.new(doc).to_hash
48
+ end
49
+ end
50
+
51
+
52
+ end
@@ -0,0 +1,205 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.epaslaugos.lt/services/authentication"
3
+ elementFormDefault="qualified" xmlns="http://www.epaslaugos.lt/services/authentication">
4
+
5
+ <xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd" />
6
+ <xs:import namespace="http://www.w3.org/2001/10/xml-exc-c14n#" schemaLocation="exc-c14n.xsd" />
7
+ <xs:import namespace="http://viisp.ivpk.lt/systemHealth" schemaLocation="systemHealth.xsd" />
8
+
9
+ <xs:element name="authenticationRequest">
10
+ <xs:complexType>
11
+ <xs:sequence>
12
+ <xs:element name="pid" type="xs:string" />
13
+ <xs:element name="serviceTarget" type="serviceTarget" minOccurs="0" />
14
+ <xs:element name="authenticationProvider" type="authenticationProvider" minOccurs="0" maxOccurs="unbounded" />
15
+ <xs:element name="authenticationAttribute" type="authenticationAttribute" minOccurs="0" maxOccurs="unbounded" />
16
+ <xs:element name="userInformation" type="userInformation" minOccurs="0" maxOccurs="unbounded" />
17
+ <xs:element name="proxyAuthenticationAttribute" type="authenticationAttribute" minOccurs="0" maxOccurs="unbounded" />
18
+ <xs:element name="proxyUserInformation" type="userInformation" minOccurs="0" maxOccurs="unbounded" />
19
+ <xs:element name="postbackUrl" type="xs:anyURI" minOccurs="0" />
20
+ <xs:element name="customData" type="xs:string" minOccurs="0" />
21
+ <xs:element ref="dsig:Signature" />
22
+ </xs:sequence>
23
+ <xs:attribute name="id" type="xs:ID" use="optional" />
24
+ </xs:complexType>
25
+ </xs:element>
26
+
27
+ <xs:element name="authenticationResponse">
28
+ <xs:complexType>
29
+ <xs:sequence>
30
+ <xs:element name="ticket" type="ticket" />
31
+ <xs:element ref="dsig:Signature" />
32
+ </xs:sequence>
33
+ <xs:attribute name="id" type="xs:ID" use="optional" />
34
+ </xs:complexType>
35
+ </xs:element>
36
+
37
+ <xs:element name="authenticationDataRequest">
38
+ <xs:complexType>
39
+ <xs:sequence>
40
+ <xs:element name="pid" type="xs:string" />
41
+ <xs:element name="ticket" type="ticket" />
42
+ <xs:element name="includeSourceData" type="xs:boolean" minOccurs="0" />
43
+ <xs:element ref="dsig:Signature" />
44
+ </xs:sequence>
45
+ <xs:attribute name="id" type="xs:ID" use="optional" />
46
+ </xs:complexType>
47
+ </xs:element>
48
+
49
+ <xs:element name="authenticationDataResponse">
50
+ <xs:complexType>
51
+ <xs:sequence>
52
+ <xs:element name="authenticationProvider" type="authenticationProvider" />
53
+ <xs:element name="authenticationAttribute" type="authenticationAttributePair" minOccurs="0" maxOccurs="unbounded" />
54
+ <xs:element name="userInformation" type="userInformationPair" minOccurs="0" maxOccurs="unbounded" />
55
+ <xs:element name="proxyAuthenticationAttribute" type="authenticationAttributePair" minOccurs="0" maxOccurs="unbounded"/>
56
+ <xs:element name="proxyUserInformation" type="userInformationPair" minOccurs="0" maxOccurs="unbounded"/>
57
+ <xs:element name="customData" type="xs:string" minOccurs="0" />
58
+ <xs:element name="sourceData" type="authenticationSourceData" minOccurs="0" />
59
+ <xs:element ref="dsig:Signature" />
60
+ </xs:sequence>
61
+ <xs:attribute name="id" type="xs:ID" use="optional" />
62
+ </xs:complexType>
63
+ </xs:element>
64
+
65
+ <xs:element name="invalidSignatureException" />
66
+ <xs:element name="invalidXmlException" />
67
+
68
+ <xs:complexType name="authenticationAttributePair">
69
+ <xs:sequence>
70
+ <xs:element name="attribute" type="authenticationAttribute" />
71
+ <xs:element name="value" type="xs:string" />
72
+ </xs:sequence>
73
+ </xs:complexType>
74
+
75
+ <xs:complexType name="userInformationPair">
76
+ <xs:sequence>
77
+ <xs:element name="information" type="userInformation" />
78
+ <xs:element name="value">
79
+ <xs:complexType>
80
+ <xs:choice>
81
+ <xs:element name="stringValue" type="xs:string" />
82
+ <xs:element name="dateValue" type="xs:date" />
83
+ </xs:choice>
84
+ </xs:complexType>
85
+ </xs:element>
86
+ </xs:sequence>
87
+ </xs:complexType>
88
+
89
+ <xs:simpleType name="ticket">
90
+ <xs:restriction base="xs:string">
91
+ <xs:maxLength value="512" />
92
+ </xs:restriction>
93
+ </xs:simpleType>
94
+
95
+ <xs:simpleType name="serviceTarget">
96
+ <xs:restriction base="xs:string">
97
+ <xs:enumeration value="citizen" />
98
+ <xs:enumeration value="business" />
99
+ <xs:enumeration value="provider" />
100
+ </xs:restriction>
101
+ </xs:simpleType>
102
+
103
+ <xs:simpleType name="authenticationProvider">
104
+ <xs:restriction base="xs:string">
105
+ <xs:enumeration value="auth.login.pass" />
106
+ <xs:enumeration value="auth.lt.identity.card" />
107
+ <xs:enumeration value="auth.lt.government.employee.card" />
108
+ <xs:enumeration value="auth.lt.bank" />
109
+ <xs:enumeration value="auth.stork">
110
+ <xs:annotation>
111
+ <xs:documentation>Reikšmė nebegaliojanti, palikta dėl išorinių sistemų palaikymo</xs:documentation>
112
+ </xs:annotation>
113
+ </xs:enumeration>
114
+ <xs:enumeration value="auth.eidas" />
115
+ <xs:enumeration value="auth.tsl.identity.card" >
116
+ <xs:annotation>
117
+ <xs:documentation>Reikšmė nebegaliojanti, palikta dėl išorinių sistemų palaikymo</xs:documentation>
118
+ </xs:annotation>
119
+ </xs:enumeration>
120
+ <xs:enumeration value="auth.signatureProvider" />
121
+ <xs:enumeration value="auth.iltu.identity.card" />
122
+ </xs:restriction>
123
+ </xs:simpleType>
124
+
125
+ <xs:simpleType name="authenticationAttribute">
126
+ <xs:restriction base="xs:string">
127
+ <xs:enumeration value="lt-personal-code" />
128
+ <xs:enumeration value="lt-company-code" />
129
+ <xs:enumeration value="lt-government-employee-code" />
130
+ <xs:enumeration value="stork-eid">
131
+ <xs:annotation>
132
+ <xs:documentation>Reikšmė nebegaliojanti, palikta dėl išorinių sistemų palaikymo</xs:documentation>
133
+ </xs:annotation>
134
+ </xs:enumeration>
135
+ <xs:enumeration value="tsl-serial-number">
136
+ <xs:annotation>
137
+ <xs:documentation>Reikšmė nebegaliojanti, palikta dėl išorinių sistemų palaikymo</xs:documentation>
138
+ </xs:annotation>
139
+ </xs:enumeration>
140
+ <xs:enumeration value="eidas-eid" />
141
+ <xs:enumeration value="login" />
142
+ <xs:enumeration value="iltu-personal-code" />
143
+ </xs:restriction>
144
+ </xs:simpleType>
145
+
146
+ <xs:simpleType name="userInformation">
147
+ <xs:restriction base="xs:string">
148
+ <xs:enumeration value="id" />
149
+ <xs:enumeration value="firstName" />
150
+ <xs:enumeration value="lastName" />
151
+ <xs:enumeration value="address" />
152
+ <xs:enumeration value="email" />
153
+ <xs:enumeration value="phoneNumber" />
154
+ <xs:enumeration value="birthday" />
155
+ <xs:enumeration value="companyName" />
156
+ <xs:enumeration value="nationality" />
157
+ <xs:enumeration value="proxyType" />
158
+ <xs:enumeration value="proxySource" />
159
+ </xs:restriction>
160
+ </xs:simpleType>
161
+
162
+ <xs:simpleType name="proxyType">
163
+ <xs:restriction base="xs:string">
164
+ <xs:enumeration value="generic" />
165
+ <xs:enumeration value="service" />
166
+ <xs:enumeration value="external" />
167
+ <xs:enumeration value="legal" />
168
+ </xs:restriction>
169
+ </xs:simpleType>
170
+
171
+ <xs:simpleType name="proxySource">
172
+ <xs:restriction base="xs:string">
173
+ <xs:enumeration value="JAR"/>
174
+ <xs:enumeration value="GR"/>
175
+ <xs:enumeration value="NIRVAR"/>
176
+ <xs:enumeration value="AUTHORIZATION_REGISTER"/>
177
+ <xs:enumeration value="VIISP"/>
178
+ <xs:enumeration value="BANKLINK"/>
179
+ <xs:enumeration value="eIDAS"/>
180
+ <xs:enumeration value="USERNAME_PASSWORD"/>
181
+ </xs:restriction>
182
+ </xs:simpleType>
183
+
184
+ <xs:complexType name="authenticationSourceData">
185
+ <xs:sequence>
186
+ <xs:element name="type" type="authenticationSourceType" />
187
+ <xs:element name="parameter" type="authenticationSourceParameter" maxOccurs="unbounded" />
188
+ </xs:sequence>
189
+ </xs:complexType>
190
+
191
+ <xs:simpleType name="authenticationSourceType">
192
+ <xs:restriction base="xs:string">
193
+ <xs:enumeration value="SAML" />
194
+ <xs:enumeration value="BANKLINK" />
195
+ </xs:restriction>
196
+ </xs:simpleType>
197
+
198
+ <xs:complexType name="authenticationSourceParameter">
199
+ <xs:simpleContent>
200
+ <xs:extension base="xs:string">
201
+ <xs:attribute name="name" type="xs:string" />
202
+ </xs:extension>
203
+ </xs:simpleContent>
204
+ </xs:complexType>
205
+ </xs:schema>
@@ -0,0 +1,39 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE schema
3
+ PUBLIC "-//W3C//DTD XMLSchema 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd"
4
+ [
5
+ <!ATTLIST schema
6
+ xmlns:ec CDATA #FIXED 'http://www.w3.org/2001/10/xml-exc-c14n#'>
7
+ <!ENTITY ec 'http://www.w3.org/2001/10/xml-exc-c14n#'>
8
+ <!ENTITY % p ''>
9
+ <!ENTITY % s ''>
10
+ ]>
11
+
12
+
13
+ <!-- Schema for Exclusive Canonicalization
14
+ http://www.w3.org/2001/10/xml-exc-c14n#
15
+ $Revision: 1.1 $ on $Date: 2002/07/11 17:26:47 $ by $Author: reagle $
16
+
17
+ Copyright 2002 The Internet Society and W3C (Massachusetts Institute
18
+ of Technology, Institut National de Recherche en Informatique et en
19
+ Automatique, Keio University). All Rights Reserved.
20
+ http://www.w3.org/Consortium/Legal/
21
+
22
+ This document is governed by the W3C Software License [1] as described
23
+ in the FAQ [2].
24
+
25
+ [1] http://www.w3.org/Consortium/Legal/copyright-software-19980720
26
+ [2] http://www.w3.org/Consortium/Legal/IPR-FAQ-20000620.html#DTD
27
+ -->
28
+
29
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
30
+ xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"
31
+ targetNamespace="http://www.w3.org/2001/10/xml-exc-c14n#"
32
+ version="0.1" elementFormDefault="qualified">
33
+ <element name="InclusiveNamespaces"
34
+ type="ec:InclusiveNamespaces"/>
35
+
36
+ <complexType name="InclusiveNamespaces">
37
+ <attribute name="PrefixList" type="NMTOKENS"/>
38
+ </complexType>
39
+ </schema>