Commit 00f070e
2017-10-23 01:34:12
1 parent
cfaecc8
Changed files (4)
airport
app
controllers
spec
controllers
saml-kit
lib
saml
kit
airport/app/controllers/application_controller.rb
@@ -4,8 +4,8 @@ class ApplicationController < ActionController::Base
before_action :authenticate!
def current_user
- return nil unless session[:user_id].present?
- @current_user ||= User.new(id: session[:user_id], email: session[:email])
+ return nil unless session[:user].present?
+ @current_user ||= User.new(session[:user].with_indifferent_access)
end
def current_user?
airport/app/controllers/sessions_controller.rb
@@ -10,8 +10,7 @@ class SessionsController < ApplicationController
def create
saml_response = Saml::Kit::SamlResponse.parse(params[:SAMLResponse])
- session[:user_id] = saml_response.name_id
- session[:email] = saml_response[:email]
+ session[:user] = { id: saml_response.name_id }.merge(saml_response.attributes)
redirect_to dashboard_path
end
airport/spec/controllers/sessions_controller_spec.rb
@@ -37,8 +37,7 @@ describe SessionsController do
it 'logs the correct user in' do
post :create, params: { SAMLResponse: saml_response }
- expect(session[:email]).to eql(email)
- expect(session[:user_id]).to eql(user_id)
+ expect(session[:user]).to eql(id: user_id, 'email' => email, 'blah' => 'blah')
expect(response).to redirect_to(dashboard_path)
end
end
saml-kit/lib/saml/kit/saml_response.rb
@@ -3,22 +3,25 @@ module Saml
class SamlResponse
def initialize(xml)
@xml = xml
- @hash = Hash.from_xml(xml)
+ @xml_hash = Hash.from_xml(xml)
end
def name_id
- @hash['Response']['Assertion']['Subject']['NameID']
+ @xml_hash['Response']['Assertion']['Subject']['NameID']
end
def [](key)
- item = @hash['Response']['Assertion']['AttributeStatement']['Attribute'].find do |x|
- x['Name'] == key.to_s
- end
- item['AttributeValue']
+ attributes[key]
+ end
+
+ def attributes
+ @attributes ||= Hash[@xml_hash['Response']['Assertion']['AttributeStatement']['Attribute'].map do |item|
+ [item['Name'].to_sym, item['AttributeValue']]
+ end].with_indifferent_access
end
def acs_url
- @hash['Response']['Destination']
+ @xml_hash['Response']['Destination']
end
def to_xml