main
1# frozen_string_literal: true
2
3module Saml
4 module Kit
5 module Bindings
6 # This class is responsible for
7 # serializing/deserializing SAML
8 # documents using the HTTP Post
9 # binding specification.
10 # https://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf
11 # {include:file:spec/saml/kit/bindings/http_post_spec.rb}
12 class HttpPost < Binding
13 include Serializable
14
15 def initialize(location:)
16 super(binding: Saml::Kit::Bindings::HTTP_POST, location: location)
17 end
18
19 def serialize(builder, relay_state: nil)
20 builder.destination = location
21 document = builder.build
22 xml = document.to_xml
23 saml_params = {
24 document.query_string_parameter => Base64.strict_encode64(xml),
25 }
26 saml_params['RelayState'] = relay_state if relay_state.present?
27 [location, saml_params]
28 end
29
30 def deserialize(params, configuration: Saml::Kit.configuration)
31 xml = decode(saml_param_from(params))
32 Saml::Kit::Document.to_saml_document(
33 xml,
34 configuration: configuration
35 )
36 end
37 end
38 end
39 end
40end