Class: RubyApp::Elements::Mobile::Documents::Authentication::OpenId::AuthenticationDocument

Inherits:
AuthenticationDocument show all
Defined in:
lib/ruby_app/elements/mobile/documents/authentication/open_id/authentication_document.rb

Direct Known Subclasses

EmailAuthenticationDocument

Instance Attribute Summary

Attributes inherited from RubyApp::Elements::Mobile::Document

#links, #metadata, #pages, #scripts, #stylesheets

Attributes inherited from RubyApp::Element

#attributes

Instance Method Summary collapse

Methods inherited from RubyApp::Elements::Mobile::Document

#hide, #page, #show

Methods inherited from RubyApp::Element

#element_id, get_element

Methods included from Mixins::ConfigurationMixin

#configuration

Methods included from Mixins::TranslateMixin

#localize, #translate

Methods included from Mixins::TemplateMixin

#exclude_parent_template, #exclude_parent_template?, #get_cache, #get_default_template, #get_template, #get_template_name, #get_templates, #template_path

Methods included from Mixins::RenderMixin

#content_for, #get_cache, #get_default_template, #get_templates, #render

Constructor Details

#initialize(identifier) ⇒ AuthenticationDocument

Returns a new instance of AuthenticationDocument.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ruby_app/elements/mobile/documents/authentication/open_id/authentication_document.rb', line 24

def initialize(identifier)
  super()

  self.page.loaded do |element, event|
    unless @consumer
      @consumer = ::OpenID::Consumer.new(RubyApp::Session.data, nil)
      request = @consumer.begin(identifier)
      self.process_request(request)
      url = request.redirect_url(RubyApp::Request.url, RubyApp::Request.url)
      RubyApp::Log.debug("OPENID    --> #{url.inspect}")
      event.go(url)
    else
      RubyApp::Log.debug("OPENID    <-- #{RubyApp::Request.url.inspect}")
      response = @consumer.complete(RubyApp::Request.query, RubyApp::Request.url)
      case response.status
        when ::OpenID::Consumer::SUCCESS
          self.process_response(response)
        when ::OpenID::Consumer::FAILURE
          RubyApp::Log.error("OPENID    #{response.class}")
          RubyApp::Log.error("OPENID    #{response.message.inspect}")
          raise RubyApp::Exceptions::AuthenticationFailedException.new(response.message)
      end
      self.hide(event)
    end
  end

end

Instance Method Details

#create_identity_from_response(response) ⇒ Object



59
60
61
# File 'lib/ruby_app/elements/mobile/documents/authentication/open_id/authentication_document.rb', line 59

def create_identity_from_response(response)
  return RubyApp::Session::Identity.new(response.identity_url)
end

#process_request(request) ⇒ Object



52
53
# File 'lib/ruby_app/elements/mobile/documents/authentication/open_id/authentication_document.rb', line 52

def process_request(request)
end

#process_response(response) ⇒ Object



55
56
57
# File 'lib/ruby_app/elements/mobile/documents/authentication/open_id/authentication_document.rb', line 55

def process_response(response)
  RubyApp::Session.identity = self.create_identity_from_response(response)
end