33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/onelogin/ruby-saml-bm/authrequest.rb', line 33
def create_authentication_xml_doc(settings)
uuid = "_" + UUID.new.generate
time = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
request_doc = REXML::Document.new
root = request_doc.add_element "samlp:AuthnRequest", { "xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol" }
root.attributes['ID'] = uuid
root.attributes['IssueInstant'] = time
root.attributes['Version'] = "2.0"
if settings.assertion_consumer_service_url != nil
root.attributes["AssertionConsumerServiceURL"] = settings.assertion_consumer_service_url
end
if settings.issuer != nil
issuer = root.add_element "saml:Issuer", { "xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion" }
issuer.text = settings.issuer
end
if settings.name_identifier_format != nil
root.add_element "samlp:NameIDPolicy", {
"xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol",
"AllowCreate" => "true",
"Format" => settings.name_identifier_format
}
end
if settings.authn_context != nil
requested_context = root.add_element "samlp:RequestedAuthnContext", {
"xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol",
"Comparison" => "exact",
}
class_ref = requested_context.add_element "saml:AuthnContextClassRef", {
"xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion",
}
class_ref.text = settings.authn_context
end
request_doc
end
|