ruby-saml-mod 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/onelogin/saml/auth_request.rb +44 -38
- data/spec/response_spec.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70a7eb538a2bbed9d2269ccf27a1ae560a40734c
|
4
|
+
data.tar.gz: dca9f7dd1a7e5e7d3a7e8967af606b3688144c09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1be665813508c314582bebac318758085c74ca7fd3621c58e6df191df83639981eb48fa3b3d6cbad8047765962abddd6fb920a8b8d0f9062d2075293f1ba8d87
|
7
|
+
data.tar.gz: a9d34492f6c2e8feb08a1bccccb2a53545c88ef336bc1cfb8345fff663ccbee7857bc338970d233877a8b295b44d03779b5f5cadcdeaa2655b5af57acb24e134
|
@@ -1,47 +1,53 @@
|
|
1
|
-
module Onelogin::Saml
|
2
|
-
class AuthRequest
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
raise NotImplementedError
|
1
|
+
module Onelogin::Saml
|
2
|
+
class AuthRequest
|
3
|
+
|
4
|
+
attr_reader :settings, :id, :request_xml, :forward_url
|
5
|
+
|
6
|
+
def initialize(settings)
|
7
|
+
@settings = settings
|
9
8
|
end
|
10
|
-
|
11
|
-
def self.
|
12
|
-
|
13
|
-
|
14
|
-
requested_authn_context: settings.requested_authn_context,
|
15
|
-
assertion_consumer_service_url: Array(settings.assertion_consumer_service_url).first,
|
16
|
-
name_identifier_format: settings.name_identifier_format
|
17
|
-
})
|
9
|
+
|
10
|
+
def self.create(settings)
|
11
|
+
ar = AuthRequest.new(settings)
|
12
|
+
ar.generate_request
|
18
13
|
end
|
14
|
+
|
15
|
+
def generate_request
|
16
|
+
@id = Onelogin::Saml::AuthRequest.generate_unique_id(42)
|
17
|
+
issue_instant = Onelogin::Saml::AuthRequest.get_timestamp
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
@request_xml =
|
20
|
+
"<samlp:AuthnRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" ID=\"#{@id}\" Version=\"2.0\" IssueInstant=\"#{issue_instant}\" ProtocolBinding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST\" AssertionConsumerServiceURL=\"#{Array(settings.assertion_consumer_service_url).first}\">" +
|
21
|
+
"<saml:Issuer xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">#{@settings.issuer}</saml:Issuer>\n" +
|
22
|
+
"<samlp:NameIDPolicy xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" Format=\"#{@settings.name_identifier_format}\" AllowCreate=\"true\"></samlp:NameIDPolicy>\n"
|
23
|
+
|
24
|
+
if @settings.requested_authn_context
|
25
|
+
@request_xml += "<samlp:RequestedAuthnContext xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" Comparison=\"exact\">"
|
26
|
+
@request_xml += "<saml:AuthnContextClassRef xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">#{@settings.requested_authn_context}</saml:AuthnContextClassRef>"
|
27
|
+
@request_xml += "</samlp:RequestedAuthnContext>\n"
|
27
28
|
end
|
29
|
+
|
30
|
+
@request_xml += "</samlp:AuthnRequest>"
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
xmlns:saml="#{Onelogin::NAMESPACES['saml']}"
|
33
|
-
ID="#{self.id}"
|
34
|
-
Version="2.0"
|
35
|
-
ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
|
36
|
-
AssertionConsumerServiceURL=\"#{self.assertion_consumer_service_url}\"
|
37
|
-
IssueInstant="#{self.issue_instant}">
|
38
|
-
|
39
|
-
<saml:Issuer>#{self.issuer}</saml:Issuer>
|
40
|
-
<samlp:NameIDPolicy Format="#{self.name_identifier_format}" AllowCreate="true"></samlp:NameIDPolicy>
|
32
|
+
deflated_request = Zlib::Deflate.deflate(@request_xml, 9)[2..-5]
|
33
|
+
base64_request = Base64.strict_encode64(deflated_request)
|
34
|
+
encoded_request = CGI.escape(base64_request)
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
@forward_url = @settings.idp_sso_target_url + (@settings.idp_sso_target_url.include?("?") ? "&" : "?") + "SAMLRequest=" + encoded_request
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def self.generate_unique_id(length)
|
42
|
+
chars = ("a".."f").to_a + ("0".."9").to_a
|
43
|
+
chars_len = chars.size
|
44
|
+
unique_id = ("a".."f").to_a[rand(6)]
|
45
|
+
2.upto(length) { |i| unique_id << chars[rand(chars_len)] }
|
46
|
+
unique_id
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.get_timestamp
|
50
|
+
Time.new.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|
data/spec/response_spec.rb
CHANGED
@@ -164,9 +164,9 @@ describe Onelogin::Saml::Response do
|
|
164
164
|
:idp_slo_target_url => "http://example.com/logout.php"
|
165
165
|
)
|
166
166
|
|
167
|
-
|
167
|
+
forward_url = Onelogin::Saml::AuthRequest::create(settings)
|
168
168
|
prefix = "http://example.com/login.php?SAMLRequest="
|
169
|
-
expect(
|
169
|
+
expect(forward_url[0...prefix.size]).to eql(prefix)
|
170
170
|
|
171
171
|
request = Onelogin::Saml::LogoutRequest::generate(name_qualifier, name_id, session_index, settings)
|
172
172
|
prefix = "http://example.com/logout.php?SAMLRequest="
|
@@ -181,9 +181,9 @@ describe Onelogin::Saml::Response do
|
|
181
181
|
:idp_slo_target_url => "http://example.com/logout.php?param=foo"
|
182
182
|
)
|
183
183
|
|
184
|
-
|
184
|
+
forward_url = Onelogin::Saml::AuthRequest::create(settings)
|
185
185
|
prefix = "http://example.com/login.php?param=foo&SAMLRequest="
|
186
|
-
expect(
|
186
|
+
expect(forward_url[0...prefix.size]).to eql(prefix)
|
187
187
|
|
188
188
|
request = Onelogin::Saml::LogoutRequest::generate(name_qualifier, name_id, session_index, settings)
|
189
189
|
prefix = "http://example.com/logout.php?param=foo&SAMLRequest="
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-saml-mod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OneLogin LLC
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2014-
|
17
|
+
date: 2014-11-06 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: libxml-ruby
|