Class: SSO::Signo

Inherits:
Base
  • Object
show all
Defined in:
lib/sso/signo.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#controller, #user

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from SSO::Base

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env


3
4
5
# File 'lib/sso/signo.rb', line 3

def env
  @env
end

#headersObject (readonly)

Returns the value of attribute headers


3
4
5
# File 'lib/sso/signo.rb', line 3

def headers
  @headers
end

Instance Method Details

#authenticate!Object


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sso/signo.rb', line 31

def authenticate!
  if (username = request.cookies['username'])
    # we already have cookie
    identifier                  = "#{Setting['signo_url']}/user/#{username}"
    headers['WWW-Authenticate'] = Rack::OpenID.build_header({ :identifier => identifier })
    controller.render :text => '', :status => 401
  else
    # we have no cookie yet so we plain redirect to OpenID provider to login
    controller.redirect_to 
  end
end

#authenticated?Boolean


22
23
24
25
26
27
28
29
# File 'lib/sso/signo.rb', line 22

def authenticated?
  if (response = env[Rack::OpenID::RESPONSE])
    store if (result = parse_open_id(response))
    result
  else
    false
  end
end

#available?Boolean


7
8
9
# File 'lib/sso/signo.rb', line 7

def available?
  Setting['signo_sso'] && defined?(Rack::OpenID) && !controller.api_request?
end

#expiration_urlObject


51
52
53
# File 'lib/sso/signo.rb', line 51

def expiration_url
  "#{login_url}&notice=expired"
end

#login_urlObject


43
44
45
# File 'lib/sso/signo.rb', line 43

def 
  "#{Setting['signo_url']}?return_url=#{URI.escape(request.url)}"
end

#logout_urlObject


47
48
49
# File 'lib/sso/signo.rb', line 47

def logout_url
  "#{Setting['signo_url']}/logout?return_url=#{URI.escape(root_url)}"
end

#support_expiration?Boolean


18
19
20
# File 'lib/sso/signo.rb', line 18

def support_expiration?
  true
end

#support_login?Boolean

by default we support login however when @failed flag is set it means that first try of #authenticate! failed and we don't to try it again, because we would encounter endless loop


14
15
16
# File 'lib/sso/signo.rb', line 14

def support_login?
  !@failed
end