Skip to content

Commit e9a91c1

Browse files
author
Lordnibbler
committed
Merge pull request #108 from onelogin/namespacing-change
Change namespacing from Onelogin::Saml to Onelogin::Rubysaml
2 parents 2016b77 + 14528d1 commit e9a91c1

20 files changed

+209
-197
lines changed

README.md

Lines changed: 70 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Ruby SAML [![Build Status](https://secure.travis-ci.org/onelogin/ruby-saml.png)](http://travis-ci.org/onelogin/ruby-saml)
22

3+
## Updating from 0.7.x to 0.8.x
4+
Version `0.8.0` changes the namespace of the gem from `Onelogin::Saml` to `Onelogin::RubySaml`. Please update your implementations of the gem accordingly.
5+
6+
## Overview
7+
38
The Ruby SAML library is for implementing the client side of a SAML authorization, i.e. it provides a means for managing authorization initialization and confirmation requests from identity providers.
49

510
SAML authorization is a two step process and you are expected to implement support for both.
@@ -9,113 +14,113 @@ SAML authorization is a two step process and you are expected to implement suppo
914
This is the first request you will get from the identity provider. It will hit your application at a specific URL (that you've announced as being your SAML initialization point). The response to this initialization, is a redirect back to the identity provider, which can look something like this (ignore the saml_settings method call for now):
1015

1116
```ruby
12-
def init
13-
request = Onelogin::Saml::Authrequest.new
14-
redirect_to(request.create(saml_settings))
15-
end
17+
def init
18+
request = Onelogin::RubySaml::Authrequest.new
19+
redirect_to(request.create(saml_settings))
20+
end
1621
```
1722

1823
Once you've redirected back to the identity provider, it will ensure that the user has been authorized and redirect back to your application for final consumption, this is can look something like this (the authorize_success and authorize_failure methods are specific to your application):
1924

2025
```ruby
21-
def consume
22-
response = Onelogin::Saml::Response.new(params[:SAMLResponse])
23-
response.settings = saml_settings
24-
25-
if response.is_valid? && user = current_account.users.find_by_email(response.name_id)
26-
authorize_success(user)
27-
else
28-
authorize_failure(user)
29-
end
30-
end
26+
def consume
27+
response = Onelogin::RubySaml::Response.new(params[:SAMLResponse])
28+
response.settings = saml_settings
29+
30+
if response.is_valid? && user = current_account.users.find_by_email(response.name_id)
31+
authorize_success(user)
32+
else
33+
authorize_failure(user)
34+
end
35+
end
3136
```
3237

3338
In the above there are a few assumptions in place, one being that the response.name_id is an email address. This is all handled with how you specify the settings that are in play via the saml_settings method. That could be implemented along the lines of this:
3439

3540
```ruby
36-
def saml_settings
37-
settings = Onelogin::Saml::Settings.new
38-
39-
settings.assertion_consumer_service_url = "http://#{request.host}/saml/finalize"
40-
settings.issuer = request.host
41-
settings.idp_sso_target_url = "https://app.onelogin.com/saml/signon/#{OneLoginAppId}"
42-
settings.idp_cert_fingerprint = OneLoginAppCertFingerPrint
43-
settings.name_identifier_format = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
44-
# Optional for most SAML IdPs
45-
settings.authn_context = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"
46-
47-
settings
48-
end
41+
def saml_settings
42+
settings = Onelogin::RubySaml::Settings.new
43+
44+
settings.assertion_consumer_service_url = "http://#{request.host}/saml/finalize"
45+
settings.issuer = request.host
46+
settings.idp_sso_target_url = "https://app.onelogin.com/saml/signon/#{OneLoginAppId}"
47+
settings.idp_cert_fingerprint = OneLoginAppCertFingerPrint
48+
settings.name_identifier_format = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
49+
# Optional for most SAML IdPs
50+
settings.authn_context = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"
51+
52+
settings
53+
end
4954
```
5055

5156
What's left at this point, is to wrap it all up in a controller and point the initialization and consumption URLs in OneLogin at that. A full controller example could look like this:
5257

5358
```ruby
54-
# This controller expects you to use the URLs /saml/init and /saml/consume in your OneLogin application.
55-
class SamlController < ApplicationController
56-
def init
57-
request = Onelogin::Saml::Authrequest.new
58-
redirect_to(request.create(saml_settings))
59-
end
59+
# This controller expects you to use the URLs /saml/init and /saml/consume in your OneLogin application.
60+
class SamlController < ApplicationController
61+
def init
62+
request = Onelogin::RubySaml::Authrequest.new
63+
redirect_to(request.create(saml_settings))
64+
end
6065

61-
def consume
62-
response = Onelogin::Saml::Response.new(params[:SAMLResponse])
63-
response.settings = saml_settings
66+
def consume
67+
response = Onelogin::RubySaml::Response.new(params[:SAMLResponse])
68+
response.settings = saml_settings
6469

65-
if response.is_valid? && user = current_account.users.find_by_email(response.name_id)
66-
authorize_success(user)
67-
else
68-
authorize_failure(user)
69-
end
70+
if response.is_valid? && user = current_account.users.find_by_email(response.name_id)
71+
authorize_success(user)
72+
else
73+
authorize_failure(user)
7074
end
75+
end
7176

72-
private
77+
private
7378

74-
def saml_settings
75-
settings = Onelogin::Saml::Settings.new
79+
def saml_settings
80+
settings = Onelogin::RubySaml::Settings.new
7681

77-
settings.assertion_consumer_service_url = "http://#{request.host}/saml/consume"
78-
settings.issuer = request.host
79-
settings.idp_sso_target_url = "https://app.onelogin.com/saml/signon/#{OneLoginAppId}"
80-
settings.idp_cert_fingerprint = OneLoginAppCertFingerPrint
81-
settings.name_identifier_format = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
82-
# Optional for most SAML IdPs
83-
settings.authn_context = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"
82+
settings.assertion_consumer_service_url = "http://#{request.host}/saml/consume"
83+
settings.issuer = request.host
84+
settings.idp_sso_target_url = "https://app.onelogin.com/saml/signon/#{OneLoginAppId}"
85+
settings.idp_cert_fingerprint = OneLoginAppCertFingerPrint
86+
settings.name_identifier_format = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
87+
# Optional for most SAML IdPs
88+
settings.authn_context = "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"
8489

85-
settings
86-
end
90+
settings
8791
end
92+
end
8893
```
8994

9095
If are using saml:AttributeStatement to transfare metadata, like the user name, you can access all the attributes through response.attributes. It
9196
contains all the saml:AttributeStatement with its 'Name' as a indifferent key and the one saml:AttributeValue as value.
9297

9398
```ruby
94-
response = Onelogin::Saml::Response.new(params[:SAMLResponse])
95-
response.settings = saml_settings
99+
response = Onelogin::RubySaml::Response.new(params[:SAMLResponse])
100+
response.settings = saml_settings
96101

97-
response.attributes[:username]
102+
response.attributes[:username]
98103
```
99104

100105
## Service Provider Metadata
101106

102107
To form a trusted pair relationship with the IdP, the SP (you) need to provide metadata XML
103108
to the IdP for various good reasons. (Caching, certificate lookups, relaying party permissions, etc)
104109

105-
The class Onelogin::Saml::Metadata takes care of this by reading the Settings and returning XML. All
110+
The class Onelogin::RubySaml::Metadata takes care of this by reading the Settings and returning XML. All
106111
you have to do is add a controller to return the data, then give this URL to the IdP administrator.
107112
The metdata will be polled by the IdP every few minutes, so updating your settings should propagate
108113
to the IdP settings.
109114

110115
```ruby
111-
class SamlController < ApplicationController
112-
# ... the rest of your controller definitions ...
113-
def metadata
114-
settings = Account.get_saml_settings
115-
meta = Onelogin::Saml::Metadata.new
116-
render :xml => meta.generate(settings)
117-
end
116+
class SamlController < ApplicationController
117+
# ... the rest of your controller definitions ...
118+
def metadata
119+
settings = Account.get_saml_settings
120+
meta = Onelogin::RubySaml::Metadata.new
121+
render :xml => meta.generate(settings)
118122
end
123+
end
119124
```
120125

121126
## Clock Drift
@@ -127,7 +132,7 @@ First, ensure that both systems synchronize their clocks, using for example the
127132
Even then you may experience intermittent issues though, because the clock of the Identity Provider may drift slightly ahead of your system clocks. To allow for a small amount of clock drift you can initialize the response passing in an option named `:allowed_clock_drift`. Its value must be given in a number (and/or fraction) of seconds. The value given is added to the current time at which the response is validated before it's tested against the `NotBefore` assertion. For example:
128133

129134
```ruby
130-
response = Onelogin::Saml::Response.new(params[:SAMLResponse], :allowed_clock_drift => 1)
135+
response = Onelogin::RubySaml::Response.new(params[:SAMLResponse], :allowed_clock_drift => 1)
131136
```
132137

133138
Make sure to keep the value as comfortably small as possible to keep security risks to a minimum.

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# RubySaml Changelog
2+
3+
### 0.8.0 (Feb 21, 2014)
4+
Changed namespace of the gem from `Onelogin::Saml` to `Onelogin::RubySaml`. Please update your implementations of the gem accordingly.
5+
6+
### 0.7.3 (Feb 20, 2014)
7+
Updated gem dependencies to be compatible with Ruby 1.8.7-p374 and 1.9.3-p448. Removed unnecessary `canonix` gem dependency.

lib/onelogin/ruby-saml/authrequest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
require "rexml/xpath"
77

88
module Onelogin
9-
module Saml
9+
module RubySaml
1010
include REXML
1111
class Authrequest
1212
def create(settings, params = {})

lib/onelogin/ruby-saml/logging.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Simplistic log class when we're running in Rails
22
module Onelogin
3-
module Saml
3+
module RubySaml
44
class Logging
55
def self.debug(message)
66
return if !!ENV["ruby-saml/testing"]

lib/onelogin/ruby-saml/logoutrequest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require "cgi"
55

66
module Onelogin
7-
module Saml
7+
module RubySaml
88
include REXML
99
class Logoutrequest
1010

lib/onelogin/ruby-saml/logoutresponse.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require "zlib"
55

66
module Onelogin
7-
module Saml
7+
module RubySaml
88
class Logoutresponse
99

1010
ASSERTION = "urn:oasis:names:tc:SAML:2.0:assertion"

lib/onelogin/ruby-saml/metadata.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
require "uri"
44

55
# Class to return SP metadata based on the settings requested.
6-
# Return this XML in a controller, then give that URL to the the
6+
# Return this XML in a controller, then give that URL to the the
77
# IdP administrator. The IdP will poll the URL and your settings
88
# will be updated automatically
99
module Onelogin
10-
module Saml
10+
module RubySaml
1111
include REXML
1212
class Metadata
1313
def generate(settings)

lib/onelogin/ruby-saml/response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Only supports SAML 2.0
66
module Onelogin
7-
module Saml
7+
module RubySaml
88

99
class Response
1010
ASSERTION = "urn:oasis:names:tc:SAML:2.0:assertion"

lib/onelogin/ruby-saml/settings.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Onelogin
2-
module Saml
2+
module RubySaml
33
class Settings
44
def initialize(overrides = {})
55
config = DEFAULTS.merge(overrides)

lib/onelogin/ruby-saml/validation_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Onelogin
2-
module Saml
2+
module RubySaml
33
class ValidationError < StandardError
44
end
55
end

0 commit comments

Comments
 (0)