Class: OpenamAuth::Openam

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/openam_auth/openam.rb

Constant Summary collapse

"/identity/getCookieNameForToken"
IS_TOKEN_VALID =
"/identity/isTokenValid"
USER_ATTRIBUTES =
"/identity/attributes"
LOGIN_URL =
"/UI/Login?goto="
LOGOUT_URL =
"/identity/logout"

Instance Method Summary collapse

Constructor Details

#initializeOpenam

Returns a new instance of Openam.



14
15
16
# File 'lib/openam_auth/openam.rb', line 14

def initialize
  @base_url = OpenamConfig.openam_url
end

Instance Method Details



18
19
20
21
# File 'lib/openam_auth/openam.rb', line 18

def cookie_name
  response = self.class.post("#{@base_url}#{COOKIE_NAME_FOR_TOKEN}", {})
  response.body.split('=').last.strip
end

#login_urlObject



38
39
40
# File 'lib/openam_auth/openam.rb', line 38

def 
  "#{@base_url}#{LOGIN_URL}"
end

#logout(token) ⇒ Object



42
43
44
# File 'lib/openam_auth/openam.rb', line 42

def logout(token)
  self.class.get("#{@base_url}#{LOGOUT_URL}?subjectid=#{token}", {})
end

#openam_user(token_cookie_name, token) ⇒ Object



33
34
35
36
# File 'lib/openam_auth/openam.rb', line 33

def openam_user(token_cookie_name, token)
  self.class.cookies({ token_cookie_name => token })
  self.class.post("#{@base_url}#{USER_ATTRIBUTES}", {:subjectid => token})
end


23
24
25
26
# File 'lib/openam_auth/openam.rb', line 23

def token_cookie(request, cookie_name)
  token_cookie = CGI.unescape(request.cookies.fetch(cookie_name, nil).to_s.gsub('+', '%2B'))
  token_cookie != '' ? token_cookie : nil
end

#user_hash(response) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/openam_auth/openam.rb', line 46

def user_hash(response)
  opensso_user = Hash.new{ |h,k| h[k] = Array.new }
  attribute_name = ''
  lines = response.split(/\n/)
  lines.each do |line|
    line = line.strip
    if line.match(/^userdetails.attribute.name=/)
      attribute_name = line.gsub(/^userdetails.attribute.name=/, '').strip
    elsif line.match(/^userdetails.attribute.value=/)
      opensso_user[attribute_name] << line.gsub(/^userdetails.attribute.value=/, '').strip
    end
  end
  opensso_user
end

#valid_token?(token) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/openam_auth/openam.rb', line 28

def valid_token?(token)
  response = self.class.get("#{@base_url}#{IS_TOKEN_VALID}?tokenid=#{token}", {})
  response.body.split('=').last.strip == 'true'
end