Skip to content

Commit

Permalink
Merge pull request #461 from sishen/1.0-beta
Browse files Browse the repository at this point in the history
Add saml provider to Utils::CAMELIZE_SPECIAL list and return user_info in
  • Loading branch information
Michael Bleigh committed Sep 10, 2011
2 parents 9f81195 + 06392f1 commit c9bfc2a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions lib/omniauth/core.rb
Expand Up @@ -103,6 +103,7 @@ module Utils
'cas' => 'CAS',
'trademe' => 'TradeMe',
'ldap' => 'LDAP',
'saml' => 'SAML',
'google_oauth2' => 'GoogleOAuth2'
}

Expand Down
1 change: 1 addition & 0 deletions oa-core/lib/omniauth/core.rb
Expand Up @@ -104,6 +104,7 @@ module Utils
'cas' => 'CAS',
'trademe' => 'TradeMe',
'ldap' => 'LDAP',
'saml' => 'SAML',
'google_oauth2' => 'GoogleOAuth2'
}

Expand Down
31 changes: 20 additions & 11 deletions oa-enterprise/lib/omniauth/strategies/saml.rb
Expand Up @@ -8,9 +8,9 @@ class SAML
autoload :AuthResponse, 'omniauth/strategies/saml/auth_response'
autoload :ValidationError, 'omniauth/strategies/saml/validation_error'
autoload :XMLSecurity, 'omniauth/strategies/saml/xml_security'

@@settings = {}

def initialize(app, options={})
super(app, :saml)
@@settings = {
Expand All @@ -21,30 +21,39 @@ def initialize(app, options={})
:name_identifier_format => options[:name_identifier_format] || "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
}
end

def request_phase
request = OmniAuth::Strategies::SAML::AuthRequest.new
redirect(request.create(@@settings))
end

def callback_phase
begin
response = OmniAuth::Strategies::SAML::AuthResponse.new(request.params['SAMLResponse'])
response.settings = @@settings
@response = OmniAuth::Strategies::SAML::AuthResponse.new(request.params['SAMLResponse'])
@response.settings = @@settings
@name_id = response.name_id
return fail!(:invalid_ticket, 'Invalid SAML Ticket') if @name_id.nil? || @name_id.empty?
super
rescue ArgumentError => e
fail!(:invalid_ticket, 'Invalid SAML Response')
end
end
end

def auth_hash
OmniAuth::Utils.deep_merge(super, {
'uid' => @name_id
'uid' => @name_id,
'user_info' => user_info
})
end

end

def user_info
name = @response.attributes[:name] || "#{@response.attributes[:firstname]} #{@response.attributes[:lastname]}"
{
:name => name,
:email => @response.attributes[:email]
}
end

end
end
end
8 changes: 4 additions & 4 deletions oa-enterprise/lib/omniauth/strategies/saml/auth_response.rb
Expand Up @@ -4,7 +4,7 @@ module OmniAuth
module Strategies
class SAML
class AuthResponse

ASSERTION = "urn:oasis:names:tc:SAML:2.0:assertion"
PROTOCOL = "urn:oasis:names:tc:SAML:2.0:protocol"
DSIG = "http://www.w3.org/2000/09/xmldsig#"
Expand Down Expand Up @@ -47,7 +47,7 @@ def attributes
name = attr_element.attributes["Name"]
value = attr_element.elements.first.text

result[name] = value
result[name.downcase] = value
end

result.keys.each do |key|
Expand Down Expand Up @@ -134,8 +134,8 @@ def parse_time(node, attribute)
Time.parse(node.attributes[attribute])
end
end

end
end
end
end
end

0 comments on commit c9bfc2a

Please sign in to comment.